import { TaskStage } from '@prisma/client';

export const STAGE_LABELS = [
  'Inbox',
  'In Progress',
  'Code Review & QA',
  'Done',
] as const;

export type StageLabel = (typeof STAGE_LABELS)[number];

const toDb: Record<string, TaskStage> = {
  Inbox: TaskStage.Backlog,
  Backlog: TaskStage.Backlog,
  'In Progress': TaskStage.InProgress,
  'Code Review & QA': TaskStage.CodeReviewQA,
  Done: TaskStage.Done,
};

const fromDb: Record<TaskStage, StageLabel> = {
  Backlog: 'Inbox',
  InProgress: 'In Progress',
  CodeReviewQA: 'Code Review & QA',
  Done: 'Done',
};

export function stageToDb(label: string): TaskStage {
  const s = toDb[label as StageLabel];
  if (!s) throw new Error(`Invalid stage: ${label}`);
  return s;
}

export function stageFromDb(stage: TaskStage): StageLabel {
  return fromDb[stage];
}

export function stageIndex(label: string): number {
  return STAGE_LABELS.indexOf(label as StageLabel);
}
