import { z } from "zod";
import { video_tags, videos } from "../db/schema";

export const postVideoInputSchema = z.object({
  title: z.string(),
  description: z.string(),
  youtube_id: z.string(),
  thumbnail: z.string(),
  duration: z.number(),
  size: z.number(),
  likes: z.number(),
  views: z.number(),
  published_at: z.string(),
});

export const postVideoOutputSchema = z.object({
  success: z.boolean(),
  message: z.string(),
});

export const getVideosInputSchema = z.object({
  limit: z.number().optional().describe("Maximum number of videos to return"),
  offset: z.number().optional().describe("Number of videos to skip"),
  sortBy: z
    .string()
    .optional()
    .describe("Field to sort by (title, published_at, views, likes)"),
  sortOrder: z.string().optional().describe("Sort order (asc, desc)"),
});

export const getVideosOutputSchema = z.object({
  success: z.boolean(),
  message: z.string(),
  videos: z.array(
    z.object({
      id: z.string(),
      title: z.string(),
      duration: z.number(),
      description: z.string(),
      thumbnail: z.string(),
      size: z.number(),
      likes: z.number(),
      views: z.number(),
      published_at: z.string(),
      videoTags: z.array(
        z.object({
          id: z.string(),
          name: z.string(),
        })
      ),
    })
  ),
  pagination: z.object({
    total: z.number(),
    limit: z.number(),
    offset: z.number(),
    hasMore: z.boolean(),
  }),
});

export const getVideoByTagsInputSchema = z.object({
  tags: z.array(z.string()),
});

export const getVideoByTagsOutputSchema = z.object({
  success: z.boolean(),
  message: z.string(),
  videos: z.array(
    z.object({
      id: z.string(),
      title: z.string(),
    })
  ),
});

export const getVideoByIdInputSchema = z.object({
  id: z.string().min(1, "ID cannot be empty"),
});

export const getVideoByIdOutputSchema = z.object({
  success: z.boolean(),
  message: z.string(),
  video: z.object({
    id: z.string(),
    title: z.string(),
    duration: z.number(),
    description: z.string(),
    thumbnail: z.string(),
    size: z.number(),
    likes: z.number(),
    views: z.number(),
    published_at: z.string(),
    videoTags: z.array(
      z.object({
        id: z.string(),
        name: z.string(),
      })
    ),
  }),
});

export const videosSchema = videos.$inferSelect;
export const videoTagsSchema = video_tags.$inferSelect;
