export type ProposalStatusValue = "DRAFT" | "IN_PROGRESS" | "SUBMITTED" | "ARCHIVED";

const ALLOWED_TRANSITIONS: Record<ProposalStatusValue, ProposalStatusValue[]> = {
  DRAFT: ["IN_PROGRESS", "ARCHIVED"],
  IN_PROGRESS: ["SUBMITTED", "ARCHIVED"],
  SUBMITTED: ["ARCHIVED"],
  ARCHIVED: [],
};

export function parseProposalStatus(value: unknown): ProposalStatusValue | null {
  if (value === "DRAFT" || value === "IN_PROGRESS" || value === "SUBMITTED" || value === "ARCHIVED") {
    return value;
  }

  return null;
}

export function canTransitionProposalStatus(from: ProposalStatusValue, to: ProposalStatusValue) {
  if (from === to) {
    return true;
  }

  return ALLOWED_TRANSITIONS[from].includes(to);
}

export function getProposalStatusLabel(status: ProposalStatusValue) {
  if (status === "DRAFT") {
    return "Borrador";
  }

  if (status === "IN_PROGRESS") {
    return "En progreso";
  }

  if (status === "SUBMITTED") {
    return "Enviada";
  }

  return "Archivada";
}
