-- CreateTable
CREATE TABLE `CoursePackage` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `coursePackageId` VARCHAR(191) NOT NULL,
    `title` VARCHAR(191) NOT NULL,
    `description` TEXT NULL,
    `thumbnailUrl` VARCHAR(191) NULL,
    `totalPrice` DECIMAL(10, 2) NOT NULL DEFAULT 0,
    `totalOfferPrice` DECIMAL(10, 2) NOT NULL DEFAULT 0,
    `isActive` BOOLEAN NOT NULL DEFAULT true,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `CoursePackage_coursePackageId_key`(`coursePackageId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CoursePackageCategory` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `coursePackageId` VARCHAR(191) NOT NULL,
    `categoryId` VARCHAR(191) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    UNIQUE INDEX `CoursePackageCategory_coursePackageId_categoryId_key`(`coursePackageId`, `categoryId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CoursePackageSubcategory` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `coursePackageCategoryId` INTEGER NOT NULL,
    `subcategoryId` VARCHAR(191) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    UNIQUE INDEX `CoursePackageSubcategory_coursePackageCategoryId_subcategory_key`(`coursePackageCategoryId`, `subcategoryId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CoursePackageVideo` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `coursePackageSubcategoryId` INTEGER NOT NULL,
    `videoId` VARCHAR(191) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    UNIQUE INDEX `CoursePackageVideo_coursePackageSubcategoryId_videoId_key`(`coursePackageSubcategoryId`, `videoId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `CoursePackageCategory` ADD CONSTRAINT `CoursePackageCategory_coursePackageId_fkey` FOREIGN KEY (`coursePackageId`) REFERENCES `CoursePackage`(`coursePackageId`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CoursePackageCategory` ADD CONSTRAINT `CoursePackageCategory_categoryId_fkey` FOREIGN KEY (`categoryId`) REFERENCES `Category`(`categoryId`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CoursePackageSubcategory` ADD CONSTRAINT `CoursePackageSubcategory_coursePackageCategoryId_fkey` FOREIGN KEY (`coursePackageCategoryId`) REFERENCES `CoursePackageCategory`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CoursePackageSubcategory` ADD CONSTRAINT `CoursePackageSubcategory_subcategoryId_fkey` FOREIGN KEY (`subcategoryId`) REFERENCES `Subcategory`(`subcategoryId`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CoursePackageVideo` ADD CONSTRAINT `CoursePackageVideo_coursePackageSubcategoryId_fkey` FOREIGN KEY (`coursePackageSubcategoryId`) REFERENCES `CoursePackageSubcategory`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CoursePackageVideo` ADD CONSTRAINT `CoursePackageVideo_videoId_fkey` FOREIGN KEY (`videoId`) REFERENCES `Video`(`videoId`) ON DELETE CASCADE ON UPDATE CASCADE;
