-- CreateTable
CREATE TABLE "Cliente" (
    "id" BIGSERIAL NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT (now() AT TIME ZONE 'utc'),
    "updated_at" TIMESTAMP(3) NOT NULL DEFAULT (now() AT TIME ZONE 'utc'),
    "name" TEXT NOT NULL,
    "cedula" BIGINT NOT NULL,
    "ubicacion" TEXT NOT NULL DEFAULT '.',
    "grupo_estudio" TEXT,
    "empleado" BOOLEAN NOT NULL DEFAULT false,
    "avatar_url" TEXT,
    "telefono" TEXT,
    "idciat" TEXT,

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

-- CreateTable
CREATE TABLE "Planilla" (
    "id" BIGSERIAL NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT (now() AT TIME ZONE 'utc'),
    "updated_at" TIMESTAMP(3) NOT NULL DEFAULT (now() AT TIME ZONE 'utc'),
    "fecha_desde" TIMESTAMP(3) NOT NULL,
    "fecha_hasta" TIMESTAMP(3) NOT NULL,
    "titulo" TEXT NOT NULL,
    "total" DECIMAL(65,30),
    "estado" TEXT NOT NULL DEFAULT 'pagado',
    "fecha_anulado" TIMESTAMP(3),
    "empleado_id" BIGINT NOT NULL,
    "creador_id" UUID,
    "anulador_id" UUID,

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

-- CreateTable
CREATE TABLE "TareaRealizada" (
    "id" BIGSERIAL NOT NULL,
    "empleado_id" BIGINT NOT NULL,
    "planilla_id" BIGINT,
    "titulo" TEXT NOT NULL,
    "precio" DOUBLE PRECISION,
    "estado" TEXT NOT NULL DEFAULT 'pendiente',
    "observacion" TEXT,
    "fecha" TIMESTAMP(3) NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT (now() AT TIME ZONE 'utc'),
    "tipo" TEXT NOT NULL DEFAULT '',
    "fecha_anulado" TIMESTAMP(3),
    "creador_id" UUID NOT NULL,
    "anulador_id" UUID,

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

-- CreateTable
CREATE TABLE "Asistencia" (
    "id" BIGSERIAL NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT (now() AT TIME ZONE 'utc'),
    "updated_at" TIMESTAMP(3) NOT NULL DEFAULT (now() AT TIME ZONE 'utc'),
    "entrada" TIMESTAMP(3) DEFAULT (now() AT TIME ZONE 'utc'),
    "salida" TIMESTAMP(3),
    "historial" JSONB,
    "observacion" TEXT,
    "estado" TEXT DEFAULT 'pendiente',
    "fecha_anulado" TIMESTAMP(3),
    "empleado_id" BIGINT NOT NULL,
    "creador_id" UUID NOT NULL,
    "modificado_id" UUID,
    "anulador_id" UUID,

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

-- CreateIndex
CREATE UNIQUE INDEX "Cliente_cedula_key" ON "Cliente"("cedula");

-- AddForeignKey
ALTER TABLE "Planilla" ADD CONSTRAINT "Planilla_empleado_id_fkey" FOREIGN KEY ("empleado_id") REFERENCES "Cliente"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TareaRealizada" ADD CONSTRAINT "TareaRealizada_empleado_id_fkey" FOREIGN KEY ("empleado_id") REFERENCES "Cliente"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Asistencia" ADD CONSTRAINT "Asistencia_empleado_id_fkey" FOREIGN KEY ("empleado_id") REFERENCES "Cliente"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
