-- AlterEnum
ALTER TYPE "platform_automation"."AutomationTaskType" ADD VALUE 'DINGTALK_SYNC';

-- CreateTable
CREATE TABLE "platform_automation"."dingtalk_sync_configs" (
    "id" UUID NOT NULL,
    "task_code" TEXT NOT NULL,
    "form_uuid" TEXT,
    "app_type" TEXT,
    "fieldMapping" JSONB NOT NULL DEFAULT '{}',
    "sync_direction" TEXT NOT NULL,
    "search_condition" JSONB,
    "lookback_minutes" INTEGER NOT NULL DEFAULT 30,
    "metadata" JSONB NOT NULL DEFAULT '{}',
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_automation"."dingtalk_leave_codes" (
    "id" UUID NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "year" INTEGER,
    "category" TEXT NOT NULL,
    "is_active" BOOLEAN NOT NULL DEFAULT true,
    "metadata" JSONB NOT NULL DEFAULT '{}',
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "dingtalk_sync_configs_task_code_key" ON "platform_automation"."dingtalk_sync_configs"("task_code");

-- CreateIndex
CREATE UNIQUE INDEX "dingtalk_leave_codes_code_key" ON "platform_automation"."dingtalk_leave_codes"("code");
