-- CreateEnum
CREATE TYPE "public"."MarketingMeetingStatus" AS ENUM ('requested', 'scheduled', 'completed', 'cancelled');

-- CreateTable
CREATE TABLE "public"."MarketingMeeting" (
    "id" TEXT NOT NULL,
    "department" "public"."DepartmentKey" NOT NULL,
    "title" TEXT NOT NULL,
    "agenda" TEXT NOT NULL,
    "status" "public"."MarketingMeetingStatus" NOT NULL DEFAULT 'requested',
    "requestedById" TEXT,
    "requestedByName" TEXT NOT NULL,
    "participantNames" JSONB NOT NULL,
    "suggestedTimes" JSONB NOT NULL,
    "scheduledFor" TIMESTAMP(3),
    "completedAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "public"."MarketingCommitment" (
    "id" TEXT NOT NULL,
    "meetingId" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT,
    "ownerName" TEXT,
    "dueDate" TIMESTAMP(3),
    "status" TEXT NOT NULL DEFAULT 'pendiente',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "MarketingMeeting_department_status_scheduledFor_idx" ON "public"."MarketingMeeting"("department", "status", "scheduledFor");

-- CreateIndex
CREATE INDEX "MarketingCommitment_meetingId_dueDate_idx" ON "public"."MarketingCommitment"("meetingId", "dueDate");

-- AddForeignKey
ALTER TABLE "public"."MarketingMeeting" ADD CONSTRAINT "MarketingMeeting_requestedById_fkey" FOREIGN KEY ("requestedById") REFERENCES "public"."User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."MarketingCommitment" ADD CONSTRAINT "MarketingCommitment_meetingId_fkey" FOREIGN KEY ("meetingId") REFERENCES "public"."MarketingMeeting"("id") ON DELETE CASCADE ON UPDATE CASCADE;
