// frontend/lib/types.ts
// Phase 2 backend schemas.py 와 1:1 대응하는 타입.
export type Tone = "blue" | "violet" | "coral" | "green" | "amber" | "ink" | "faint";
export type Status = "todo" | "doing" | "waiting" | "review" | "done";
export type Prio = "높음" | "보통" | "낮음";

export type { IconName } from "@/components/icons/paths";
export type { NavItem } from "@/lib/nav";

export interface Person {
  id: string; // "jiwoo"
  name: string; // "지우"
  initial: string; // "지"
  color: string; // "var(--blue)" | "oklch(0.66 0.13 200)"
  is_me: boolean;
}

export interface Project {
  id: string;
  folder_id: string;
  parent_id: string | null;
  name: string;
  tone: Tone;
  sort_order: number;
  pinned: boolean;
  task_count: number;
  children: Project[];
}

export interface Folder {
  id: string; // "work" | "life"
  name: string; // "업무" | "개인"
  tone: Tone;
  icon: string; // "folder" | "heart"
  sort_order: number;
  is_system: boolean;
  projects: Project[];
}

export interface TaskComment {
  id: string;
  task_id: string;
  person_id: string;
  text: string;
  created_at: string;
}

export interface Task {
  id: string;
  project_id: string;
  parent_id: string | null;
  title: string;
  status: Status;
  assignee_id: string | null;
  due: string | null; // ISO date "2026-06-08"
  prio: Prio;
  notes: string; // HTML
  est: string;
  delegated: boolean;
  sort_order: number;
  created_at: string;
  updated_at: string;
  comments: TaskComment[];
  children: Task[];
}

export interface Risk {
  kind: "지연 위험" | "업무 쏠림" | "의존성";
  icon: "clock" | "scale" | "link";
  tone: "coral" | "amber" | "violet";
  text: string; // 강조어는 **굵게** 마크다운
  task_id: string | null;
  cta: string | null;
}

export interface ScaffoldResult {
  kind: string;
  icon: string;
  items: { title: string; est: string }[];
  created: boolean;
  created_task_ids: string[];
}

// ---------- 인박스 (Phase 4) ----------
export type InboxKind = "text" | "voice" | "image";
export type InboxStatus = "new" | "classified" | "confirmed" | "dismissed";
export type RouteType = "task" | "event" | "idea";
export type Sphere = "work" | "life";

/** 백엔드 inbox_classification 1:1 */
export interface Classification {
  id: string;
  inbox_item_id: string;
  type: RouteType;
  sphere: Sphere;
  project_id: string | null;
  proj_label: string;
  tone: Tone;
  due_text: string | null;
  when_text: string | null;
  extra: string | null;
  reason: string;
  confidence: number;
  model: string;
  created_at: string;
}

/** 백엔드 inbox_item (+ 최신 classification) */
export interface InboxItem {
  id: string;
  kind: InboxKind;
  raw: string;
  status: InboxStatus;
  created_at: string;
  materialized_task_id: string | null;
  classification: Classification | null;
}

export interface CaptureResult {
  item: InboxItem;
  classification: Classification;
}

export interface ConfirmResult {
  item: InboxItem;
  task?: Task;
}

/** UI 전용: thinking/error 추가 */
export type UiInboxStatus = InboxStatus | "thinking" | "error";
export interface UiInboxItem extends Omit<InboxItem, "status"> {
  status: UiInboxStatus;
  time: string;
  fresh?: boolean;
  fallbackUsed?: boolean;
}

// ---------- 대시보드 (Phase 5) ----------
export interface DashUser {
  name: string;
  initial: string;
}
export interface Weather {
  temp: number;
  cond: string;
  icon: string;
}
export interface DashBriefing {
  today: string;
  weather: Weather;
  commute: string;
  sleep: string;
  note: string; // HTML
}
export interface ScheduleItem {
  id: string;
  time: string;
  title: string;
  tag: string;
  dur: string;
  tone: Tone;
  soon: boolean;
}
export interface ApprovalSummary {
  id: string;
  icon: string;
  tone: Tone;
  title: string;
  time: string;
}
export interface InboxRecent {
  id: string;
  kind: "text" | "voice" | "image";
  raw: string;
  type: string;
  proj_label: string;
  tone: Tone;
}
export interface DashTaskSummaryItem {
  id: string;
  title: string;
  project: string;
  prio: Prio;
}
export interface DashTaskSummary {
  open_count: number;
  items: DashTaskSummaryItem[];
}
export interface DashGoal {
  id: string;
  title: string;
  pct: number;
  sub: string;
  tone: Tone;
}
export interface Badges {
  appr: number;
  task: number;
  noti: number;
}
export interface Dashboard {
  user: DashUser;
  briefing: DashBriefing;
  saved_today: string;
  today_routed: number;
  schedule: ScheduleItem[];
  task_summary: DashTaskSummary;
  goals: DashGoal[];
  approvals_summary: ApprovalSummary[];
  inbox_recent: InboxRecent[];
  badges: Badges;
}
