export type Status = "todo" | "doing" | "done";
export type Priority = "low" | "med" | "high";
export type ProjectStatus = "active" | "paused" | "done";
export type Port = "n" | "s" | "e" | "w";
export type BoardKind = "board" | "flow";

export type NodeType =
  | "sticky"
  | "rect"
  | "ellipse"
  | "diamond"
  | "text"
  | "start"
  | "process"
  | "decision"
  | "document"
  | "taskcard";

export type Project = {
  id: string;
  name: string;
  description: string;
  status: ProjectStatus;
  createdAt: string;
  updatedAt: string;
};

export type Task = {
  id: string;
  title: string;
  body: string;
  status: Status;
  priority: Priority;
  projectId: string | null;
  dueAt: string | null;
  reminderId: string | null;
  noteIds: string[];
  source?: { kind: "note" | "board" | "flow"; id: string; nodeId?: string };
  createdAt: string;
  updatedAt: string;
};

export type Note = {
  id: string;
  title: string;
  body: string;
  tags: string[];
  projectId: string | null;
  taskIds: string[];
  createdAt: string;
  updatedAt: string;
};

export type Reminder = {
  id: string;
  title: string;
  dueAt: string;
  done: boolean;
  taskId: string | null;
  projectId: string | null;
  createdAt: string;
};

/** Something you are waiting on from someone else, and may need to chase. */
export type WaitingItem = {
  id: string;
  title: string;
  /** Who it is with — a person, team, vendor. Free text. */
  who: string;
  notes: string;
  projectId: string | null;
  /** When you started waiting. Editable: you often log it after the fact. */
  since: string;
  /** When to chase next. Null means no follow-up planned. */
  followUpAt: string | null;
  /** How many times you have followed up, and when you last did. */
  nudges: number;
  lastNudgedAt: string | null;
  done: boolean;
  doneAt: string | null;
  createdAt: string;
  updatedAt: string;
};

/** A quick jot on the Today scratchpad. Colour indexes --color-jot-1..4. */
export type ScratchNote = {
  id: string;
  text: string;
  color: 1 | 2 | 3 | 4;
  createdAt: string;
  updatedAt: string;
};

export type BoardNode = {
  id: string;
  type: NodeType;
  x: number;
  y: number;
  w: number;
  h: number;
  text: string;
  fill?: string;
  linkedTaskId?: string;
  linkedNoteId?: string;
};

export type BoardEdge = {
  id: string;
  from: string;
  to: string;
  fromPort: Port;
  toPort: Port;
  label: string;
};

export type Stroke = {
  id: string;
  color: string;
  width: number;
  points: number[];
};

export type Board = {
  id: string;
  title: string;
  kind: BoardKind;
  projectId: string | null;
  nodes: BoardNode[];
  edges: BoardEdge[];
  strokes: Stroke[];
  createdAt: string;
  updatedAt: string;
};

export type WorkspaceData = {
  projects: Project[];
  tasks: Task[];
  notes: Note[];
  reminders: Reminder[];
  boards: Board[];
  /** Absent in books saved before this existed; always default it to []. */
  waiting: WaitingItem[];
  /** Absent in books saved before the scratchpad existed; default to []. */
  scratch: ScratchNote[];
  focusTaskId: string | null;
};
