-- CreateTable
CREATE TABLE `Depense` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `montant` INTEGER NOT NULL,
    `fastFoodId` INTEGER NOT NULL,
    `userId` INTEGER NOT NULL,
    `modePaymentId` INTEGER NULL,
    `motifDepenseId` INTEGER NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `MotifDepense` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `libelle` VARCHAR(50) NOT NULL,
    `fastFoodId` INTEGER NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `Depense` ADD CONSTRAINT `Depense_fastFoodId_fkey` FOREIGN KEY (`fastFoodId`) REFERENCES `FastFood`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Depense` ADD CONSTRAINT `Depense_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Depense` ADD CONSTRAINT `Depense_modePaymentId_fkey` FOREIGN KEY (`modePaymentId`) REFERENCES `ModePayment`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Depense` ADD CONSTRAINT `Depense_motifDepenseId_fkey` FOREIGN KEY (`motifDepenseId`) REFERENCES `MotifDepense`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `MotifDepense` ADD CONSTRAINT `MotifDepense_fastFoodId_fkey` FOREIGN KEY (`fastFoodId`) REFERENCES `FastFood`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
