-- v1.2 签到方式校验：城市派生 + 会议/系列开关 + 系列级参会人默认覆盖 + 会议级临时调整
-- 详见 docs/modules/meeting-attendance/06-data-model.md v1.2 备注章节

-- CreateEnum
CREATE TYPE "platform_meeting_attendance"."AttendanceMode" AS ENUM ('ON_SITE', 'ONLINE');

-- AlterTable: User 加工作地
ALTER TABLE "platform_iam"."users" ADD COLUMN "work_city" VARCHAR(100);

-- AlterTable: Meeting 加地点 + 开关
ALTER TABLE "platform_meeting_attendance"."meetings"
  ADD COLUMN "city" VARCHAR(100),
  ADD COLUMN "enforce_checkin_mode" BOOLEAN NOT NULL DEFAULT false;

-- AlterTable: MeetingSeries 加地点 + 开关
ALTER TABLE "platform_meeting_attendance"."meeting_series"
  ADD COLUMN "city" VARCHAR(100),
  ADD COLUMN "enforce_checkin_mode" BOOLEAN NOT NULL DEFAULT false;

-- AlterTable: MeetingRequiredAttendee 加会议级签到方式覆盖
ALTER TABLE "platform_meeting_attendance"."meeting_required_attendees"
  ADD COLUMN "checkin_mode" "platform_meeting_attendance"."AttendanceMode";

-- CreateTable: 系列级参会人默认签到方式覆盖
CREATE TABLE "platform_meeting_attendance"."meeting_series_attendee_preferences" (
    "series_id" VARCHAR(32) NOT NULL,
    "user_id" UUID NOT NULL,
    "default_checkin_mode" "platform_meeting_attendance"."AttendanceMode" NOT NULL,
    "updated_by_user_id" UUID,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

    CONSTRAINT "meeting_series_attendee_preferences_pkey" PRIMARY KEY ("series_id","user_id")
);

-- CreateIndex
CREATE INDEX "meeting_series_attendee_preferences_user_id_idx" ON "platform_meeting_attendance"."meeting_series_attendee_preferences"("user_id");

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."meeting_series_attendee_preferences"
  ADD CONSTRAINT "meeting_series_attendee_preferences_series_id_fkey"
  FOREIGN KEY ("series_id") REFERENCES "platform_meeting_attendance"."meeting_series"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_meeting_attendance"."meeting_series_attendee_preferences"
  ADD CONSTRAINT "meeting_series_attendee_preferences_user_id_fkey"
  FOREIGN KEY ("user_id") REFERENCES "platform_iam"."users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
