-- CreateEnum
CREATE TYPE "CompensationModel" AS ENUM ('PER_JOB', 'SALARY', 'HYBRID');

-- CreateTable
CREATE TABLE "TechnicianProfile" (
    "id" TEXT NOT NULL,
    "tenantId" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "phone" TEXT,
    "skills" TEXT[],
    "zoneId" TEXT,
    "compensationModel" "CompensationModel" NOT NULL DEFAULT 'PER_JOB',
    "monthlySalary" DECIMAL(10,2),
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "JobTypeRate" (
    "id" TEXT NOT NULL,
    "tenantId" TEXT NOT NULL,
    "jobType" TEXT NOT NULL,
    "rate" DECIMAL(10,2) NOT NULL,
    "description" TEXT,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "TechnicianProfile_tenantId_idx" ON "TechnicianProfile"("tenantId");

-- CreateIndex
CREATE UNIQUE INDEX "TechnicianProfile_tenantId_userId_key" ON "TechnicianProfile"("tenantId", "userId");

-- CreateIndex
CREATE INDEX "JobTypeRate_tenantId_idx" ON "JobTypeRate"("tenantId");

-- CreateIndex
CREATE UNIQUE INDEX "JobTypeRate_tenantId_jobType_key" ON "JobTypeRate"("tenantId", "jobType");

-- AddForeignKey
ALTER TABLE "TechnicianProfile" ADD CONSTRAINT "TechnicianProfile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TechnicianProfile" ADD CONSTRAINT "TechnicianProfile_zoneId_fkey" FOREIGN KEY ("zoneId") REFERENCES "Zone"("id") ON DELETE SET NULL ON UPDATE CASCADE;
