-- Store meeting-request statuses as fixed workflow values instead of free-form text.
CREATE TYPE "MeetingRequestStatus" AS ENUM (
  'DRAFT',
  'SUBMITTED',
  'UNDER_REVIEW',
  'SCHEDULED',
  'COMPLETED'
);

ALTER TABLE "meeting_requests" ALTER COLUMN "status" DROP DEFAULT;

ALTER TABLE "meeting_requests"
  ALTER COLUMN "status" TYPE "MeetingRequestStatus"
  USING (
    CASE
      WHEN UPPER("status") IN ('DRAFT', 'DRAFTED') THEN 'DRAFT'::"MeetingRequestStatus"
      WHEN UPPER("status") = 'UNDER REVIEW' OR UPPER("status") = 'UNDER_REVIEW'
        THEN 'UNDER_REVIEW'::"MeetingRequestStatus"
      WHEN UPPER("status") = 'SCHEDULED' THEN 'SCHEDULED'::"MeetingRequestStatus"
      WHEN UPPER("status") = 'COMPLETED' THEN 'COMPLETED'::"MeetingRequestStatus"
      ELSE 'SUBMITTED'::"MeetingRequestStatus"
    END
  );

ALTER TABLE "meeting_requests"
  ALTER COLUMN "status" SET DEFAULT 'DRAFT'::"MeetingRequestStatus";
