export type User = {
  id: string;
  username: string;
  email: string;
  status: string;
};

export type Team = {
  id: string;
  name: string;
  status: string;
};

export type TeamMember = {
  id: string;
  role: string;
  status: string;
  monthly_credit_limit: string;
  user: User;
};

export type AuthPayload = {
  token: string;
  user: User;
  team: Team;
};

export type Paginated<T> = {
  count: number;
  next: string | null;
  previous: string | null;
  results: T[];
};

export type Product = {
  id: string;
  title: string;
  brand: string;
  category: string;
  target_audience: string;
  specs?: Record<string, unknown>;
  description: string;
  status: string;
  cover_asset?: string | null;
  images?: Array<{ id: string; asset: string; sort_order: number; is_primary: boolean }>;
  selling_points: Array<{ id: string; title: string; detail: string; sort_order: number }>;
  created_at: string;
  updated_at: string;
};

export type Asset = {
  id: string;
  name: string;
  asset_type: string;
  source: string;
  category: string;
  description: string;
  files?: Array<{
    id: string;
    object_key: string;
    bucket: string;
    content_type: string;
    size_bytes: number;
    preview_url: string;
    is_primary: boolean;
  }>;
  created_at: string;
  updated_at: string;
};

export type ProjectStage = {
  id: string;
  stage: string;
  status: string;
};

export type ScriptVersion = {
  id: string;
  title: string;
  content: string;
  is_adopted: boolean;
  segments: Array<{ id: string; sort_order: number; duration_seconds: number; narration: string }>;
};

export type VideoSegment = {
  id: string;
  sort_order: number;
  target_duration_seconds: number;
  status: string;
  error_message: string;
  adopted_version: string | null;
  adopted_asset?: string | null;
};

export type StoryboardVersion = {
  id: string;
  prompt: string;
  is_adopted: boolean;
  frames: Array<{ id: string; sort_order: number; prompt: string; asset: string }>;
  created_at: string;
  updated_at: string;
};

export type Timeline = {
  id: string;
  name: string;
  aspect_ratio: string;
  resolution: string;
  duration_seconds: number;
  clips: Array<{ id: string; asset: string; sort_order: number; start_ms: number; duration_ms: number }>;
  subtitle_tracks?: Array<{
    id: string;
    content: Array<{ start_ms: number; text: string }>;
    style?: Record<string, unknown>;
    enabled: boolean;
  }>;
  bgm_tracks?: Array<{ id: string; asset: string; volume: number; start_ms: number }>;
  export_jobs?: Array<{
    id: string;
    status: string;
    progress: number;
    output_asset: string | null;
    error_message: string;
    created_at: string;
    updated_at: string;
  }>;
};

export type Project = {
  id: string;
  name: string;
  product: string;
  status: string;
  current_stage: string;
  failure_reason: string;
  stages: ProjectStage[];
  script_versions: ScriptVersion[];
  video_segments: VideoSegment[];
  base_asset_groups: Array<{
    id: string;
    kind: string;
    prompt: string;
    adopted_asset: string | null;
    candidate_assets: string[];
  }>;
  storyboard_versions: StoryboardVersion[];
  timeline: Timeline | null;
  created_at: string;
  updated_at: string;
};

export type BillingSummary = {
  account: {
    id: string;
    balance: string;
    reserved_balance: string;
    currency: string;
  };
  charged_total: string | number;
};

export type Ledger = {
  id: string;
  ledger_type: string;
  amount: string;
  balance_after: string;
  reason: string;
  created_at: string;
};

export type ModelConfig = {
  id: string;
  name: string;
  display_name: string;
  capability: string;
  status: string;
};

export type AITask = {
  id: string;
  task_type: string;
  status: string;
  idempotency_key: string;
  provider_task_id: string;
  created_at: string;
  updated_at: string;
};

export type Notification = {
  id: string;
  type: string;
  notification_type: string;
  priority: string;
  title: string;
  brief: string;
  body: string;
  source: string;
  project: string | null;
  project_name?: string;
  stage: string;
  owner_label: string;
  cost_label: string;
  related_url: string;
  is_read: boolean;
  unread: boolean;
  read_at: string | null;
  archived_at: string | null;
  metadata: Record<string, unknown>;
  created_at: string;
  updated_at: string;
};

export type NotificationList = Paginated<Notification> & { unread_count: number };

export type RechargeResult = {
  account: BillingSummary["account"];
  ledger: Ledger;
};
