-- CreateTable
CREATE TABLE `Utilisateur` (
    `ut_id` INTEGER NOT NULL AUTO_INCREMENT,
    `ut_nom` VARCHAR(191) NULL,
    `ut_prenom` VARCHAR(191) NULL,
    `ut_mail` VARCHAR(191) NULL,
    `ut_type_cliente` INTEGER NULL,
    `ut_age` DATETIME(3) NULL,
    `ut_nb_rdv` INTEGER NULL,
    `ut_nb_rdv_honores` INTEGER NULL,
    `ut_prix_moyen` INTEGER NULL,
    `ut_pdp` INTEGER NULL,
    `ut_panier` INTEGER NULL,
    `ut_mdp` INTEGER NULL,
    `ut_telephone` INTEGER NULL,
    `ut_date_inscription` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `ut_derniere_connexion` DATETIME(3) NULL,
    `ut_slug` VARCHAR(191) NULL,

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

-- CreateTable
CREATE TABLE `Formation` (
    `fo_id` INTEGER NOT NULL AUTO_INCREMENT,
    `fo_titre` VARCHAR(191) NULL,
    `fo_description` VARCHAR(191) NULL,
    `fo_prix` VARCHAR(191) NULL,
    `fo_miniature` LONGBLOB NULL,
    `fo_teaser` VARCHAR(191) NULL,
    `fo_date_publication` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `fo_desactive` BOOLEAN NOT NULL DEFAULT false,
    `fo_slug` VARCHAR(191) NULL,

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

-- CreateTable
CREATE TABLE `Video` (
    `vi_fo_id` INTEGER NOT NULL,
    `vi_id` INTEGER NOT NULL AUTO_INCREMENT,
    `vi_titre` VARCHAR(191) NULL,
    `vi_description` VARCHAR(191) NULL,
    `vi_etape` INTEGER NULL,
    `vi_url` VARCHAR(191) NULL,
    `vi_slug` VARCHAR(191) NULL,

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

-- CreateTable
CREATE TABLE `Commande` (
    `co_id` INTEGER NOT NULL AUTO_INCREMENT,
    `co_utilisateur` INTEGER NOT NULL,
    `co_date_creation` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `co_date_update` DATETIME(3) NULL,
    `co_slug` VARCHAR(191) NULL,
    `co_status` VARCHAR(191) NOT NULL DEFAULT 'IN PROGRESS',

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

-- CreateTable
CREATE TABLE `CommandeFormation` (
    `cof_id` INTEGER NOT NULL AUTO_INCREMENT,
    `cof_formation` INTEGER NOT NULL,
    `cof_slug` VARCHAR(191) NULL,

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

-- CreateTable
CREATE TABLE `Achat` (
    `ac_id` INTEGER NOT NULL AUTO_INCREMENT,
    `ac_utilisateur` INTEGER NOT NULL,
    `ac_formation` INTEGER NOT NULL,
    `ac_type` VARCHAR(191) NULL,
    `ac_slug` VARCHAR(191) NULL,
    `ac_date_achat` DATETIME(3) NULL,
    `ac_date_fin` DATETIME(3) NULL,

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

-- CreateTable
CREATE TABLE `Tag` (
    `ta_id` INTEGER NOT NULL AUTO_INCREMENT,
    `ta_titre` VARCHAR(191) NULL,
    `ta_slug` VARCHAR(191) NULL,

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

-- CreateTable
CREATE TABLE `TagVideo` (
    `tv_tag_id` INTEGER NOT NULL,
    `tv_video_id` INTEGER NOT NULL,

    PRIMARY KEY (`tv_tag_id`, `tv_video_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Session` (
    `ut_id` INTEGER NOT NULL,
    `createAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `expireAt` DATETIME(3) NULL,

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

-- AddForeignKey
ALTER TABLE `Video` ADD CONSTRAINT `Video_vi_fo_id_fkey` FOREIGN KEY (`vi_fo_id`) REFERENCES `Formation`(`fo_id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Commande` ADD CONSTRAINT `Commande_co_utilisateur_fkey` FOREIGN KEY (`co_utilisateur`) REFERENCES `Utilisateur`(`ut_id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CommandeFormation` ADD CONSTRAINT `CommandeFormation_cof_formation_fkey` FOREIGN KEY (`cof_formation`) REFERENCES `Formation`(`fo_id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Achat` ADD CONSTRAINT `Achat_ac_utilisateur_fkey` FOREIGN KEY (`ac_utilisateur`) REFERENCES `Utilisateur`(`ut_id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Achat` ADD CONSTRAINT `Achat_ac_formation_fkey` FOREIGN KEY (`ac_formation`) REFERENCES `Formation`(`fo_id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `TagVideo` ADD CONSTRAINT `TagVideo_tv_tag_id_fkey` FOREIGN KEY (`tv_tag_id`) REFERENCES `Tag`(`ta_id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `TagVideo` ADD CONSTRAINT `TagVideo_tv_video_id_fkey` FOREIGN KEY (`tv_video_id`) REFERENCES `Video`(`vi_id`) ON DELETE CASCADE ON UPDATE CASCADE;
