-- Migration: 20260313_project_request
-- Beschreibung: isProjectType auf deal_types + ProjectRequestDetails Tabelle

-- AlterTable: is_project_type auf deal_types
ALTER TABLE "app_crm"."deal_types" ADD COLUMN "is_project_type" BOOLEAN NOT NULL DEFAULT false;

-- CreateTable: project_request_details (1:1 mit deals, ON DELETE CASCADE)
CREATE TABLE "app_crm"."project_request_details" (
    "id"            UUID NOT NULL DEFAULT gen_random_uuid(),
    "deal_id"       UUID NOT NULL,
    "notes"         TEXT,
    "workload"      DECIMAL(5,2),
    "start_date"    TIMESTAMP(3),
    "duration"      VARCHAR(200),
    "onsite_percent" DECIMAL(5,2),
    "rate_remote"   DECIMAL(10,2),
    "rate_onsite"   DECIMAL(10,2),
    "created_at"    TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at"    TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex (unique: jeder Deal max. 1 Projektanfrage)
CREATE UNIQUE INDEX "project_request_details_deal_id_key" ON "app_crm"."project_request_details"("deal_id");

-- AddForeignKey
ALTER TABLE "app_crm"."project_request_details"
    ADD CONSTRAINT "project_request_details_deal_id_fkey"
    FOREIGN KEY ("deal_id")
    REFERENCES "app_crm"."deals"("id")
    ON DELETE CASCADE ON UPDATE CASCADE;
