import { z } from "zod";

/* ---------- Assistant ---------- */
export const AssistantSchema = z.object({
  _id: z.string(),
  name: z.string(),
  description: z.string(),
  rating: z.number(),
  reviewCount: z.number(),
  experience: z.number(),
  readings: z.number(),
  category: z.string(),
  price: z.number(),
  gender: z.enum(["male", "female"]),
  photoUrl: z.string().url(),
  externalId: z.string(),
  clientSource: z.string(),
  createdAt: z.string(),
  updatedAt: z.string(),
  personality: z.string().optional(),
});
export type Assistant = z.infer<typeof AssistantSchema>;

/* ---------- Field (для compatibilityActions) ---------- */
export const FieldSchema = z.object({
  _id: z.string(),
  actionId: z.string(),
  key: z.string(),
  title: z.string(),
  inputType: z.string(),
  model: z.string().optional(),
  property: z.string().optional(),
  createdAt: z.string(),
  updatedAt: z.string(),
});
export type Field = z.infer<typeof FieldSchema>;

/* ---------- Action ---------- */
export const ActionSchema = z.object({
  _id: z.string(),
  title: z.string(),
  minutes: z.number(),
  type: z.string(),
  imageUrl: z.string().url(),
  prompt: z.string().optional(),
  fields: z.array(FieldSchema).optional(),
  createdAt: z.string(),
  updatedAt: z.string(),
});
export type Action = z.infer<typeof ActionSchema>;

/* ---------- Partner Portrait ---------- */
export const PartnerPortraitSchema = z.object({
  _id: z.string(),
  title: z.string(),
  status: z.enum(["queued", "processing", "done", "error"]),
  result: z.string().nullable(), // Markdown text content
  imageUrl: z.string().url().nullable(),
  createdAt: z.string(),
  finishedAt: z.string().nullable(),
});
export type PartnerPortrait = z.infer<typeof PartnerPortraitSchema>;

/* ---------- Video Guide ---------- */
export const VideoGuideSchema = z.object({
  id: z.string(),
  productId: z.string(), // ID продукта для покупки
  key: z.string(),
  type: z.string(),
  name: z.string(),
  description: z.string(),
  imageUrl: z.string(),
  duration: z.string(),
  price: z.number(),
  oldPrice: z.number(),
  discount: z.number(),
  isPurchased: z.boolean(),
  videoLinkHLS: z.string(), // HLS format (.m3u8)
  videoLinkDASH: z.string(), // DASH format (.mpd)
  contentUrl: z.string().optional(), // URL to markdown content file
});
export type VideoGuide = z.infer<typeof VideoGuideSchema>;

/* ---------- Итоговый ответ /dashboard ---------- */
export const DashboardSchema = z.object({
  assistants: z.array(AssistantSchema).optional(),
  compatibilityActions: z.array(ActionSchema).optional(),
  palmActions: z.array(ActionSchema).optional(),
  meditations: z.array(ActionSchema).optional(),
  partnerPortraits: z.array(PartnerPortraitSchema).optional(),
  videoGuides: z.array(VideoGuideSchema).optional(),
});
export type DashboardData = z.infer<typeof DashboardSchema>;
