-- AlterEnum
ALTER TYPE "ContactActivityType" ADD VALUE 'POLL_VOTED';

-- AlterEnum
ALTER TYPE "ContactSource" ADD VALUE 'POLL_VOTE';

-- AlterEnum
ALTER TYPE "SignupSource" ADD VALUE 'POLL_CONVERSION';

-- AlterTable
ALTER TABLE "contacts" ADD COLUMN     "pronouns" TEXT;

-- AlterTable
ALTER TABLE "scheduling_poll_votes" ADD COLUMN     "contact_id" TEXT;

-- AlterTable
ALTER TABLE "scheduling_polls" ADD COLUMN     "auto_enroll_voters" BOOLEAN NOT NULL DEFAULT true;

-- AlterTable
ALTER TABLE "users" ADD COLUMN     "pronouns" TEXT;

-- CreateTable
CREATE TABLE "participant_needs" (
    "id" TEXT NOT NULL,
    "user_id" TEXT,
    "contact_id" TEXT,
    "needs_wheelchair" BOOLEAN NOT NULL DEFAULT false,
    "needs_ground_floor" BOOLEAN NOT NULL DEFAULT false,
    "needs_hearing_loop" BOOLEAN NOT NULL DEFAULT false,
    "needs_sign_language" BOOLEAN NOT NULL DEFAULT false,
    "other_accessibility" TEXT,
    "is_vegan" BOOLEAN NOT NULL DEFAULT false,
    "is_vegetarian" BOOLEAN NOT NULL DEFAULT false,
    "is_gluten_free" BOOLEAN NOT NULL DEFAULT false,
    "is_halal" BOOLEAN NOT NULL DEFAULT false,
    "is_kosher" BOOLEAN NOT NULL DEFAULT false,
    "has_nut_allergy" BOOLEAN NOT NULL DEFAULT false,
    "other_dietary" TEXT,
    "needs_childcare" BOOLEAN NOT NULL DEFAULT false,
    "childcare_details" TEXT,
    "needs_transportation" BOOLEAN NOT NULL DEFAULT false,
    "transportation_notes" TEXT,
    "preferred_language" TEXT DEFAULT 'en',
    "needs_translation" BOOLEAN NOT NULL DEFAULT false,
    "translation_language" TEXT,
    "visibility_consent" TEXT NOT NULL DEFAULT 'organizer_only',
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "participant_needs_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "meeting_agendas" (
    "id" TEXT NOT NULL,
    "shift_id" TEXT,
    "poll_id" TEXT,
    "title" TEXT NOT NULL,
    "items" JSONB NOT NULL DEFAULT '[]',
    "status" TEXT NOT NULL DEFAULT 'draft',
    "created_by_user_id" TEXT NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "meeting_agendas_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "meeting_minutes" (
    "id" TEXT NOT NULL,
    "agenda_id" TEXT NOT NULL,
    "notes" TEXT NOT NULL,
    "decisions" JSONB NOT NULL DEFAULT '[]',
    "attendees" JSONB NOT NULL DEFAULT '[]',
    "approved_at" TIMESTAMP(3),
    "approved_by_user_id" TEXT,
    "created_by_user_id" TEXT NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "meeting_minutes_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "action_items" (
    "id" TEXT NOT NULL,
    "agenda_id" TEXT,
    "title" TEXT NOT NULL,
    "description" TEXT,
    "assignee_user_id" TEXT,
    "due_date" TIMESTAMP(3),
    "status" TEXT NOT NULL DEFAULT 'open',
    "priority" TEXT NOT NULL DEFAULT 'normal',
    "completed_at" TIMESTAMP(3),
    "created_by_user_id" TEXT NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "action_items_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "participant_needs_user_id_key" ON "participant_needs"("user_id");

-- CreateIndex
CREATE UNIQUE INDEX "participant_needs_contact_id_key" ON "participant_needs"("contact_id");

-- CreateIndex
CREATE UNIQUE INDEX "meeting_agendas_shift_id_key" ON "meeting_agendas"("shift_id");

-- CreateIndex
CREATE UNIQUE INDEX "meeting_agendas_poll_id_key" ON "meeting_agendas"("poll_id");

-- CreateIndex
CREATE UNIQUE INDEX "meeting_minutes_agenda_id_key" ON "meeting_minutes"("agenda_id");

-- CreateIndex
CREATE INDEX "action_items_assignee_user_id_status_idx" ON "action_items"("assignee_user_id", "status");

-- CreateIndex
CREATE INDEX "action_items_due_date_idx" ON "action_items"("due_date");

-- CreateIndex
CREATE INDEX "scheduling_poll_votes_contact_id_idx" ON "scheduling_poll_votes"("contact_id");

-- AddForeignKey
ALTER TABLE "scheduling_poll_votes" ADD CONSTRAINT "scheduling_poll_votes_contact_id_fkey" FOREIGN KEY ("contact_id") REFERENCES "contacts"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "participant_needs" ADD CONSTRAINT "participant_needs_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "participant_needs" ADD CONSTRAINT "participant_needs_contact_id_fkey" FOREIGN KEY ("contact_id") REFERENCES "contacts"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "meeting_agendas" ADD CONSTRAINT "meeting_agendas_shift_id_fkey" FOREIGN KEY ("shift_id") REFERENCES "shifts"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "meeting_agendas" ADD CONSTRAINT "meeting_agendas_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "scheduling_polls"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "meeting_agendas" ADD CONSTRAINT "meeting_agendas_created_by_user_id_fkey" FOREIGN KEY ("created_by_user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "meeting_minutes" ADD CONSTRAINT "meeting_minutes_agenda_id_fkey" FOREIGN KEY ("agenda_id") REFERENCES "meeting_agendas"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "meeting_minutes" ADD CONSTRAINT "meeting_minutes_approved_by_user_id_fkey" FOREIGN KEY ("approved_by_user_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "meeting_minutes" ADD CONSTRAINT "meeting_minutes_created_by_user_id_fkey" FOREIGN KEY ("created_by_user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "action_items" ADD CONSTRAINT "action_items_agenda_id_fkey" FOREIGN KEY ("agenda_id") REFERENCES "meeting_agendas"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "action_items" ADD CONSTRAINT "action_items_assignee_user_id_fkey" FOREIGN KEY ("assignee_user_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "action_items" ADD CONSTRAINT "action_items_created_by_user_id_fkey" FOREIGN KEY ("created_by_user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

