/*
  Warnings:

  - You are about to drop the `MaintenanceTaskTemplate` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `PartsKitItem` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `ResourceRequirement` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE "MaintenanceTaskTemplate" DROP CONSTRAINT "MaintenanceTaskTemplate_catalogId_fkey";

-- DropForeignKey
ALTER TABLE "PartsKitItem" DROP CONSTRAINT "PartsKitItem_catalogId_fkey";

-- DropForeignKey
ALTER TABLE "ResourceRequirement" DROP CONSTRAINT "ResourceRequirement_catalogId_fkey";

-- DropIndex
DROP INDEX "InspectionCatalog_aircraftType_name_key";

-- DropTable
DROP TABLE "MaintenanceTaskTemplate";

-- DropTable
DROP TABLE "PartsKitItem";

-- DropTable
DROP TABLE "ResourceRequirement";

-- CreateTable
CREATE TABLE "InspectionTask" (
    "id" TEXT NOT NULL,
    "catalogId" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "estimatedHours" DOUBLE PRECISION NOT NULL,
    "skillRequired" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "InspectionPart" (
    "id" TEXT NOT NULL,
    "catalogId" TEXT NOT NULL,
    "partNumber" TEXT NOT NULL,
    "quantity" INTEGER NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "InspectionResource" (
    "id" TEXT NOT NULL,
    "catalogId" TEXT NOT NULL,
    "resourceType" TEXT NOT NULL,
    "quantity" INTEGER NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "InspectionTask_catalogId_idx" ON "InspectionTask"("catalogId");

-- CreateIndex
CREATE INDEX "InspectionPart_catalogId_idx" ON "InspectionPart"("catalogId");

-- CreateIndex
CREATE INDEX "InspectionPart_partNumber_idx" ON "InspectionPart"("partNumber");

-- CreateIndex
CREATE INDEX "InspectionResource_catalogId_idx" ON "InspectionResource"("catalogId");

-- CreateIndex
CREATE INDEX "InspectionCatalog_aircraftType_idx" ON "InspectionCatalog"("aircraftType");

-- CreateIndex
CREATE INDEX "InspectionCatalog_ataChapter_idx" ON "InspectionCatalog"("ataChapter");

-- AddForeignKey
ALTER TABLE "InspectionTask" ADD CONSTRAINT "InspectionTask_catalogId_fkey" FOREIGN KEY ("catalogId") REFERENCES "InspectionCatalog"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "InspectionPart" ADD CONSTRAINT "InspectionPart_catalogId_fkey" FOREIGN KEY ("catalogId") REFERENCES "InspectionCatalog"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "InspectionResource" ADD CONSTRAINT "InspectionResource_catalogId_fkey" FOREIGN KEY ("catalogId") REFERENCES "InspectionCatalog"("id") ON DELETE CASCADE ON UPDATE CASCADE;
