import { z } from 'zod';
import type { ToolDef, ToolPack } from '../../tool-registry.js';

/**
 * Media pack tools.
 * Note: The media API runs on a separate Fastify server (port 4100).
 * These tools target the media API paths, but the API client routes
 * them correctly since both APIs share authentication.
 */
const mediaTools: ToolDef[] = [
  {
    name: 'videos_list',
    description:
      'List videos in the media library. Filter by visibility (public, unlisted, private), ' +
      'search by title. Returns video metadata, view counts, and processing status.',
    inputSchema: {
      page: z.coerce.number().int().positive().default(1).describe('Page number'),
      limit: z.coerce.number().int().positive().max(50).default(20).describe('Items per page'),
      search: z.string().optional().describe('Search by video title'),
      visibility: z.enum(['public', 'unlisted', 'private']).optional()
        .describe('Filter by visibility'),
    },
    method: 'GET',
    path: '/api/media/videos',
    tier: 2,
  },
  {
    name: 'videos_get',
    description:
      'Get full details of a video: title, description, duration, dimensions, ' +
      'view count, reactions, processing status, and schedule info.',
    inputSchema: {
      id: z.string().describe('Video ID'),
    },
    method: 'GET',
    path: '/api/media/videos/:id',
    tier: 2,
  },
  {
    name: 'videos_update',
    description: 'Update video metadata: title, description, visibility, tags.',
    inputSchema: {
      id: z.string().describe('Video ID'),
      title: z.string().max(200).optional().describe('Video title'),
      description: z.string().max(5000).optional().describe('Video description'),
      visibility: z.enum(['public', 'unlisted', 'private']).optional().describe('Visibility setting'),
    },
    method: 'PUT',
    path: '/api/media/videos/:id',
    tier: 2,
  },
  {
    name: 'playlists_list',
    description: 'List video playlists with video count and total duration.',
    inputSchema: {
      page: z.coerce.number().int().positive().default(1).describe('Page number'),
      limit: z.coerce.number().int().positive().max(50).default(20).describe('Items per page'),
    },
    method: 'GET',
    path: '/api/media/playlists',
    tier: 2,
  },
  {
    name: 'media_analytics',
    description:
      'Get video analytics dashboard: total views, watch time, completion rates, ' +
      'top videos, traffic sources, and viewer trends.',
    inputSchema: {
      period: z.enum(['7d', '30d', '90d']).default('30d').describe('Analytics time period'),
    },
    method: 'GET',
    path: '/api/media/analytics/dashboard',
    tier: 2,
  },
  {
    name: 'media_jobs',
    description: 'Check media processing job queue: encoding, thumbnail generation, etc.',
    inputSchema: {},
    method: 'GET',
    path: '/api/media/jobs',
    tier: 2,
  },
];

export const mediaPack: ToolPack = {
  name: 'media',
  description: 'Video library, playlists, analytics, and media processing jobs',
  tools: mediaTools,
};
