-- CreateTable
CREATE TABLE "item_type" (
    "id" UUID NOT NULL,
    "code" VARCHAR(50) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "desc" TEXT,
    "status" "SettingStatus" NOT NULL DEFAULT 'ACTIVE',
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "modified_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "pricing_header" (
    "id" UUID NOT NULL,
    "item_type_id" UUID NOT NULL,
    "code" VARCHAR(50) NOT NULL,
    "name" VARCHAR(100) NOT NULL,
    "weight" INTEGER NOT NULL,
    "unit" VARCHAR(50) NOT NULL,
    "description" TEXT,
    "status" "SettingStatus" NOT NULL DEFAULT 'ACTIVE',
    "effective_date" TIMESTAMP(3) NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "modified_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "pricing_detail" (
    "id" UUID NOT NULL,
    "header_id" UUID NOT NULL,
    "item_type_id" UUID NOT NULL,
    "price_per_unit" DECIMAL(15,2) NOT NULL,
    "weight" INTEGER NOT NULL,
    "unit" VARCHAR(50) NOT NULL,
    "status" "SettingStatus" NOT NULL DEFAULT 'ACTIVE',
    "begin_effective" TIMESTAMP(3) NOT NULL,
    "end_effective" TIMESTAMP(3),
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "modified_at" TIMESTAMP(3) NOT NULL,
    "created_by" UUID NOT NULL,
    "modified_by" UUID NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "item_type_code_key" ON "item_type"("code");

-- CreateIndex
CREATE UNIQUE INDEX "pricing_header_code_key" ON "pricing_header"("code");

-- AddForeignKey
ALTER TABLE "pricing_header" ADD CONSTRAINT "pricing_header_item_type_id_fkey" FOREIGN KEY ("item_type_id") REFERENCES "item_type"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pricing_detail" ADD CONSTRAINT "pricing_detail_header_id_fkey" FOREIGN KEY ("header_id") REFERENCES "pricing_header"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pricing_detail" ADD CONSTRAINT "pricing_detail_item_type_id_fkey" FOREIGN KEY ("item_type_id") REFERENCES "item_type"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
