import type {
  ProductSummary,
  SellingPointResult,
  CreativeOption,
  Storyboard,
  VideoPrompt,
  ComplianceCheck,
} from "../../api/adVideoPlanClient";

export type EcommerceVideoStage =
  | "idle"
  | "uploading"
  | "planning"
  | "planned"
  | "imaging"
  | "imaged"
  | "rendering"
  | "partial_failed"
  | "completed"
  | "cancelled";

export type SceneTaskStatus = "idle" | "pending" | "running" | "completed" | "failed" | "cancelled";

export interface EcommerceVideoSceneTask {
  sceneId: number;
  taskId?: string;
  imageTaskId?: string;
  prompt: string;
  durationSeconds: number;
  status: SceneTaskStatus;
  progress: number;
  resultUrl?: string | null;
  imageUrl?: string | null;
  error?: string | null;
}

export interface EcommerceVideoPlanResult {
  imageUrls: string[];
  imageDescription?: string;
  summary: ProductSummary;
  selling: SellingPointResult;
  creatives: CreativeOption[];
  storyboard: Storyboard;
  videoPrompts: VideoPrompt[];
  compliance: ComplianceCheck;
}

/** Partial plan state — used as resume input when an earlier run failed mid-flow. */
export interface EcommerceVideoPlanProgress {
  imageUrls?: string[];
  imageDescription?: string;
  uploadWarnings?: string[];
  summary?: ProductSummary;
  selling?: SellingPointResult;
  creatives?: CreativeOption[];
  storyboard?: Storyboard;
  videoPrompts?: VideoPrompt[];
  compliance?: ComplianceCheck;
}

export interface EcommerceVideoDelivery {
  planResult: EcommerceVideoPlanResult | null;
  scenes: EcommerceVideoSceneTask[];
  completedCount: number;
  failedCount: number;
  totalCount: number;
}

export type PlanStep =
  | "upload"
  | "analyze"
  | "summary"
  | "selling"
  | "creative"
  | "storyboard"
  | "prompts"
  | "compliance";

export const PLAN_STEP_LABELS: Record<PlanStep, string> = {
  upload: "上传商品图",
  analyze: "分析商品图",
  summary: "生成商品理解",
  selling: "提炼卖点",
  creative: "生成广告创意",
  storyboard: "生成视频分镜",
  prompts: "生成镜头提示词",
  compliance: "合规检查",
};

/** Completed plan steps that should show as text nodes in the flow map (skip upload). */
export const PLAN_STEPS_DISPLAY: PlanStep[] = [
  "analyze", "summary", "selling", "creative", "storyboard", "prompts", "compliance",
];
