export interface ApiEnvelope<T> {
  success?: boolean;
  data?: T;
  error?: {
    code?: string;
    message?: string;
  };
  message?: string;
}

export interface UserProfile {
  id?: string | number;
  username?: string;
  email?: string;
  displayName?: string;
  avatarUrl?: string;
  roles?: string[];
}

export interface LoginResponse {
  token: string;
  tokenType?: string;
  user?: UserProfile;
}

export interface ProjectSummary {
  id: string | number;
  name?: string;
  title?: string;
  description?: string;
  status?: string;
  type?: string;
  createdAt?: string;
  updatedAt?: string;
  coverUrl?: string;
}

export interface ProjectDetail extends ProjectSummary {
  scriptAssetId?: string | number;
  metadata?: Record<string, unknown>;
}

export interface PageResult<T> {
  records?: T[];
  list?: T[];
  content?: T[];
  total?: number;
}

export type AgentRunStatus = "PENDING" | "RUNNING" | "PAUSED" | "DONE" | "FAILED" | string;

export interface AgentContextOptions {
  useScriptAsset?: boolean;
  useExistingOutline?: boolean;
  useExistingEpisodes?: boolean;
  useExistingAssets?: boolean;
  useExistingStoryboards?: boolean;
}

export interface AgentStartRequest {
  goal: string;
  runIntent?: "auto" | "script_understanding" | "continue_existing" | "quick_video" | string;
  forceRegenerate?: boolean;
  selectedSteps?: string[];
  contextOptions?: AgentContextOptions;
  idempotencyKey?: string;
}

export interface AgentStep {
  id?: string | number;
  stepKey?: string;
  stepName?: string;
  agentType?: "DECISION" | "EXECUTOR" | "SUPERVISION" | string;
  status?: AgentRunStatus;
  score?: number;
  scoreDetail?: string;
  output?: string;
  durationMs?: number;
  startedAt?: string;
  doneAt?: string;
  seq?: number;
}

export interface AgentRun {
  id: string | number;
  projectId?: string | number;
  goal?: string;
  status?: AgentRunStatus;
  createdAt?: string;
  steps?: AgentStep[];
}

export interface UploadResult {
  id?: string | number;
  assetId?: string | number;
  url?: string;
  name?: string;
}

export interface AiTask {
  id: string | number;
  projectId?: string | number;
  episodeId?: string | number;
  storyboardId?: string | number;
  taskType?: string;
  status?: string;
  resultVideoUrl?: string;
  errorMessage?: string;
  prompt?: string;
  createdAt?: string;
  updatedAt?: string;
}

export interface AssemblyTask {
  id: string | number;
  episodeId?: string | number;
  status?: string;
  shotCount?: number;
  downloadUrl?: string;
  errorMessage?: string;
  createdAt?: string;
  updatedAt?: string;
}
