-- CreateTable
CREATE TABLE "platform_meeting_attendance"."meeting_external_attendees" (
    "id" VARCHAR(32) NOT NULL,
    "meeting_id" VARCHAR(32) NOT NULL,
    "email" VARCHAR(255) NOT NULL,
    "display_name" VARCHAR(255),
    "attendee_type" VARCHAR(32),
    "response" VARCHAR(32),
    "source_role" VARCHAR(32) NOT NULL DEFAULT 'ATTENDEE',
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_meeting_attendance"."outlook_event_snapshots" (
    "id" VARCHAR(32) NOT NULL,
    "mailbox_id" VARCHAR(32) NOT NULL,
    "graph_event_id" VARCHAR(255) NOT NULL,
    "ical_uid" VARCHAR(255) NOT NULL,
    "title" VARCHAR(500) NOT NULL,
    "start_time" TIMESTAMPTZ(3),
    "end_time" TIMESTAMPTZ(3),
    "timezone" VARCHAR(64) NOT NULL,
    "event_type" VARCHAR(32) NOT NULL,
    "is_cancelled" BOOLEAN NOT NULL DEFAULT false,
    "series_master_id" VARCHAR(255),
    "organizer_email" VARCHAR(255),
    "last_modified_at" TIMESTAMPTZ(3),
    "raw_payload" JSONB,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "meeting_external_attendees_meeting_id_email_source_role_key"
ON "platform_meeting_attendance"."meeting_external_attendees"("meeting_id", "email", "source_role");

-- CreateIndex
CREATE INDEX "meeting_external_attendees_meeting_id_idx"
ON "platform_meeting_attendance"."meeting_external_attendees"("meeting_id");

-- CreateIndex
CREATE INDEX "meeting_external_attendees_email_idx"
ON "platform_meeting_attendance"."meeting_external_attendees"("email");

-- CreateIndex
CREATE UNIQUE INDEX "outlook_event_snapshots_mailbox_id_graph_event_id_key"
ON "platform_meeting_attendance"."outlook_event_snapshots"("mailbox_id", "graph_event_id");

-- CreateIndex
CREATE INDEX "outlook_event_snapshots_mailbox_id_start_time_idx"
ON "platform_meeting_attendance"."outlook_event_snapshots"("mailbox_id", "start_time");

-- CreateIndex
CREATE INDEX "outlook_event_snapshots_mailbox_id_event_type_idx"
ON "platform_meeting_attendance"."outlook_event_snapshots"("mailbox_id", "event_type");

-- CreateIndex
CREATE INDEX "outlook_event_snapshots_mailbox_id_is_cancelled_idx"
ON "platform_meeting_attendance"."outlook_event_snapshots"("mailbox_id", "is_cancelled");

-- CreateIndex
CREATE INDEX "outlook_event_snapshots_mailbox_id_series_master_id_idx"
ON "platform_meeting_attendance"."outlook_event_snapshots"("mailbox_id", "series_master_id");

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."meeting_external_attendees"
ADD CONSTRAINT "meeting_external_attendees_meeting_id_fkey"
FOREIGN KEY ("meeting_id") REFERENCES "platform_meeting_attendance"."meetings"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."outlook_event_snapshots"
ADD CONSTRAINT "outlook_event_snapshots_mailbox_id_fkey"
FOREIGN KEY ("mailbox_id") REFERENCES "platform_meeting_attendance"."outlook_sync_mailboxes"("id") ON DELETE CASCADE ON UPDATE CASCADE;
