-- CreateEnum
CREATE TYPE "AppointmentStatus" AS ENUM ('PENDIENTE', 'APROBADA', 'RECHAZADA', 'COMPLETADA', 'CANCELADA');

-- CreateTable
CREATE TABLE "Appointment" (
    "id" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "pacienteId" TEXT NOT NULL,
    "medicoId" TEXT,
    "recordId" TEXT,
    "fechaSolicitada" TIMESTAMP(3) NOT NULL,
    "estado" "AppointmentStatus" NOT NULL DEFAULT 'PENDIENTE',
    "motivoConsulta" TEXT NOT NULL,
    "motivoRechazo" TEXT,
    "notas" TEXT,
    "roomName" TEXT,

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

-- CreateIndex
CREATE UNIQUE INDEX "Appointment_recordId_key" ON "Appointment"("recordId");

-- CreateIndex
CREATE UNIQUE INDEX "Appointment_roomName_key" ON "Appointment"("roomName");

-- CreateIndex
CREATE INDEX "Appointment_pacienteId_idx" ON "Appointment"("pacienteId");

-- CreateIndex
CREATE INDEX "Appointment_medicoId_idx" ON "Appointment"("medicoId");

-- CreateIndex
CREATE INDEX "Appointment_estado_idx" ON "Appointment"("estado");

-- CreateIndex
CREATE INDEX "Appointment_fechaSolicitada_idx" ON "Appointment"("fechaSolicitada");

-- AddForeignKey
ALTER TABLE "Appointment" ADD CONSTRAINT "Appointment_pacienteId_fkey" FOREIGN KEY ("pacienteId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Appointment" ADD CONSTRAINT "Appointment_medicoId_fkey" FOREIGN KEY ("medicoId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Appointment" ADD CONSTRAINT "Appointment_recordId_fkey" FOREIGN KEY ("recordId") REFERENCES "Record"("id") ON DELETE SET NULL ON UPDATE CASCADE;
