-- CreateTable
CREATE TABLE `易耗品临时申请` (
    `id` VARCHAR(191) NOT NULL,
    `applicantName` VARCHAR(191) NULL,
    `applicantPhone` VARCHAR(191) NOT NULL,
    `department` VARCHAR(191) NULL,
    `reason` VARCHAR(191) NULL,
    `neededAt` DATETIME(3) NULL,
    `status` ENUM('PENDING', 'APPROVED', 'REJECTED', 'CANCELLED', 'COMPLETED') NOT NULL DEFAULT 'PENDING',
    `approverId` VARCHAR(191) NULL,
    `approvedAt` DATETIME(3) NULL,
    `remark` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `易耗品临时申请_applicantPhone_createdAt_idx`(`applicantPhone`, `createdAt`),
    INDEX `易耗品临时申请_status_createdAt_idx`(`status`, `createdAt`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `易耗品临时申请_易耗品条目` (
    `id` VARCHAR(191) NOT NULL,
    `requestId` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `spec` VARCHAR(191) NULL,
    `quantity` INTEGER NOT NULL,
    `unit` VARCHAR(191) NULL,
    `estimatedUnitCost` DECIMAL(65, 30) NULL,
    `remark` VARCHAR(191) NULL,
    `catalogId` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `易耗品临时申请_易耗品条目_requestId_idx`(`requestId`),
    INDEX `易耗品临时申请_易耗品条目_name_idx`(`name`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `易耗品目录` (
    `id` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `spec` VARCHAR(191) NULL,
    `unit` VARCHAR(191) NULL,
    `isActive` BOOLEAN NOT NULL DEFAULT true,

    INDEX `易耗品目录_isActive_idx`(`isActive`),
    UNIQUE INDEX `易耗品目录_name_spec_unit_key`(`name`, `spec`, `unit`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `易耗品临时申请_易耗品条目` ADD CONSTRAINT `易耗品临时申请_易耗品条目_requestId_fkey` FOREIGN KEY (`requestId`) REFERENCES `易耗品临时申请`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `易耗品临时申请_易耗品条目` ADD CONSTRAINT `易耗品临时申请_易耗品条目_catalogId_fkey` FOREIGN KEY (`catalogId`) REFERENCES `易耗品目录`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

