-- Migration: Version20251130000000
-- Description: Add Network and ReparationType entities, update Vehicule, Magasin, Marque, and Reparation entities

-- Create Network table
CREATE TABLE network (
    id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
    titre VARCHAR(255) DEFAULT NULL,
    `key` VARCHAR(255) DEFAULT NULL,
    logo VARCHAR(255) DEFAULT NULL,
    banner VARCHAR(255) DEFAULT NULL
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB;

-- Create ReparationType table
CREATE TABLE reparation_type (
    id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
    magasin_id INT DEFAULT NULL,
    titre VARCHAR(255) DEFAULT NULL,
    icon VARCHAR(255) DEFAULT NULL,
    photo VARCHAR(255) DEFAULT NULL,
    INDEX IDX_reparation_type_magasin (magasin_id),
    CONSTRAINT FK_reparation_type_magasin FOREIGN KEY (magasin_id) REFERENCES magasin (id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB;

-- Add new fields to vehicule table
ALTER TABLE vehicule ADD carte_grise_recto VARCHAR(255) DEFAULT NULL;
ALTER TABLE vehicule ADD carte_grise_verso VARCHAR(255) DEFAULT NULL;

-- Add new fields to magasin table
ALTER TABLE magasin ADD network_master TINYINT(1) DEFAULT NULL;
ALTER TABLE magasin ADD activite VARCHAR(255) DEFAULT NULL;

-- Add logo field to marque table
ALTER TABLE marque ADD logo VARCHAR(255) DEFAULT NULL;

-- Add reparationType relationship to reparation table
ALTER TABLE reparation ADD reparation_type_id INT DEFAULT NULL;
ALTER TABLE reparation ADD INDEX IDX_reparation_reparation_type (reparation_type_id);
ALTER TABLE reparation ADD CONSTRAINT FK_reparation_reparation_type FOREIGN KEY (reparation_type_id) REFERENCES reparation_type (id);

-- Add estValide field to various entities
ALTER TABLE devis ADD est_valide TINYINT(1) DEFAULT NULL;
ALTER TABLE booking ADD est_valide TINYINT(1) DEFAULT NULL;
ALTER TABLE vente ADD est_valide TINYINT(1) DEFAULT NULL;
ALTER TABLE achat ADD est_valide TINYINT(1) DEFAULT NULL;
ALTER TABLE commande ADD est_valide TINYINT(1) DEFAULT NULL;