/**
 * Workflow states for EDM entities.
 *
 * The workflow system is shared with MEMBER_OFFER and RESORT, whose states
 * ("READY_FOR_CONTENT", "CONTENT_IN_PROGRESS") describe building an offer, not
 * getting an email built, tested and signed off. `workflow_tasks.status` is a
 * free-text column, so each entity type can carry its own vocabulary without a
 * schema change — this is the EDM one.
 *
 * Order is the intended progression: build it, hand it over, test it, review the
 * tested result, publish. It is NOT enforced: a reviewer sending something back
 * from IN_REVIEW is a normal day, and a state machine that forbids it just
 * teaches people to work around the tool.
 */
export const EDM_WORKFLOW_STATES = [
  "DEV_IN_PROGRESS",
  "DEV_COMPLETED",
  "READY_FOR_TEST",
  "TESTING",
  "TESTED",
  "IN_REVIEW",
  "PUBLISHED",
  // Not part of the forward path — set when a reviewer wants changes, from any
  // state. Kept in the same list so the picker offers it everywhere.
  "CHANGE_REQUESTED",
] as const;

export type EDMWorkflowState = (typeof EDM_WORKFLOW_STATES)[number];

/**
 * States from the first version of this workflow.
 *
 * Kept only so a row written before the vocabulary changed still renders as
 * something readable instead of a raw enum. Nothing should move a task INTO
 * one of these.
 */
export const EDM_WORKFLOW_LEGACY_STATES = [
  "DRAFT",
  "VERIFIED",
  "APPROVED",
  "READY_TO_PUBLISH",
] as const;

export const EDM_WORKFLOW_ENTITY_TYPES = ["EDM_TEMPLATE", "EDM_FOLDER"] as const;
export type EDMWorkflowEntityType = (typeof EDM_WORKFLOW_ENTITY_TYPES)[number];

export const isEDMEntityType = (value: string): value is EDMWorkflowEntityType =>
  (EDM_WORKFLOW_ENTITY_TYPES as readonly string[]).includes(value);

/** First state a new EDM task starts in. */
export const EDM_WORKFLOW_INITIAL: EDMWorkflowState = "DEV_IN_PROGRESS";

/** Only PUBLISHED means "this has gone out / is cleared to go out". */
export const EDM_WORKFLOW_TERMINAL: EDMWorkflowState = "PUBLISHED";
