<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20260503195947 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Add finance base tables for fees, payments, expenses and cash movements';
    }

    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE TABLE categorie_depense (id INT AUTO_INCREMENT NOT NULL, code VARCHAR(60) NOT NULL, libelle VARCHAR(160) NOT NULL, description LONGTEXT DEFAULT NULL, ordre INT DEFAULT 1 NOT NULL, actif TINYINT DEFAULT 1 NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, ecole_id INT NOT NULL, INDEX IDX_6B8639F577EF1B1E (ecole_id), UNIQUE INDEX UNIQ_CATEGORIE_DEPENSE_ECOLE_CODE (ecole_id, code), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE depenses (id INT AUTO_INCREMENT NOT NULL, montant NUMERIC(12, 2) NOT NULL, date_depense DATE NOT NULL, beneficiaire VARCHAR(160) DEFAULT NULL, description LONGTEXT DEFAULT NULL, mode_paiement VARCHAR(40) DEFAULT NULL, reference VARCHAR(120) DEFAULT NULL, justificatif_path VARCHAR(255) DEFAULT NULL, statut VARCHAR(30) DEFAULT \'VALIDEE\' NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, ecole_id INT NOT NULL, annee_scolaire_id INT DEFAULT NULL, categorie_id INT NOT NULL, INDEX IDX_EE350ECB77EF1B1E (ecole_id), INDEX IDX_EE350ECB9331C741 (annee_scolaire_id), INDEX IDX_EE350ECBBCF5E72D (categorie_id), INDEX IDX_DEPENSE_ECOLE_DATE (ecole_id, date_depense, statut), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE echeance_paiement (id INT AUTO_INCREMENT NOT NULL, libelle VARCHAR(180) NOT NULL, montant_du NUMERIC(12, 2) NOT NULL, montant_remise NUMERIC(12, 2) DEFAULT \'0.00\' NOT NULL, montant_net NUMERIC(12, 2) NOT NULL, montant_paye NUMERIC(12, 2) DEFAULT \'0.00\' NOT NULL, date_echeance DATE DEFAULT NULL, periode VARCHAR(80) DEFAULT NULL, statut VARCHAR(30) DEFAULT \'NON_PAYE\' NOT NULL, actif TINYINT DEFAULT 1 NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, ecole_id INT NOT NULL, etudiant_id INT NOT NULL, parcours_etudiant_id INT DEFAULT NULL, annee_scolaire_id INT DEFAULT NULL, type_frais_id INT NOT NULL, regle_frais_id INT DEFAULT NULL, INDEX IDX_4E0FB37A77EF1B1E (ecole_id), INDEX IDX_4E0FB37ADDEAB1A3 (etudiant_id), INDEX IDX_4E0FB37AE677059A (parcours_etudiant_id), INDEX IDX_4E0FB37A9331C741 (annee_scolaire_id), INDEX IDX_4E0FB37A72AE4A38 (type_frais_id), INDEX IDX_4E0FB37A8F341524 (regle_frais_id), INDEX IDX_ECHEANCE_STATUS (ecole_id, annee_scolaire_id, statut, actif), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE ligne_paiement (id INT AUTO_INCREMENT NOT NULL, libelle VARCHAR(180) NOT NULL, montant NUMERIC(12, 2) NOT NULL, created_at DATETIME NOT NULL, paiement_id INT NOT NULL, ecole_id INT NOT NULL, echeance_paiement_id INT DEFAULT NULL, parcours_etudiant_id INT DEFAULT NULL, type_frais_id INT DEFAULT NULL, INDEX IDX_EE466B282A4C4478 (paiement_id), INDEX IDX_EE466B2877EF1B1E (ecole_id), INDEX IDX_EE466B286070C812 (echeance_paiement_id), INDEX IDX_EE466B28E677059A (parcours_etudiant_id), INDEX IDX_EE466B2872AE4A38 (type_frais_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE mouvement_caisse (id INT AUTO_INCREMENT NOT NULL, type VARCHAR(20) NOT NULL, source_type VARCHAR(40) DEFAULT NULL, montant NUMERIC(12, 2) NOT NULL, date_mouvement DATE NOT NULL, libelle VARCHAR(180) NOT NULL, observation LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL, ecole_id INT NOT NULL, annee_scolaire_id INT DEFAULT NULL, paiement_id INT DEFAULT NULL, depense_id INT DEFAULT NULL, INDEX IDX_C8E3DDFE77EF1B1E (ecole_id), INDEX IDX_C8E3DDFE9331C741 (annee_scolaire_id), INDEX IDX_C8E3DDFE2A4C4478 (paiement_id), INDEX IDX_C8E3DDFE41D81563 (depense_id), INDEX IDX_MOUVEMENT_CAISSE_ECOLE_DATE (ecole_id, date_mouvement, type), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE paiements (id INT AUTO_INCREMENT NOT NULL, numero_recu VARCHAR(60) NOT NULL, date_paiement DATE NOT NULL, montant_total NUMERIC(12, 2) NOT NULL, mode_paiement VARCHAR(40) DEFAULT NULL, reference VARCHAR(120) DEFAULT NULL, observation LONGTEXT DEFAULT NULL, statut VARCHAR(30) DEFAULT \'VALIDE\' NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, ecole_id INT NOT NULL, etudiant_id INT NOT NULL, annee_scolaire_id INT DEFAULT NULL, inscription_id INT DEFAULT NULL, INDEX IDX_E1B02E1277EF1B1E (ecole_id), INDEX IDX_E1B02E12DDEAB1A3 (etudiant_id), INDEX IDX_E1B02E129331C741 (annee_scolaire_id), INDEX IDX_E1B02E125DAC5993 (inscription_id), INDEX IDX_PAIEMENT_ECOLE_DATE (ecole_id, date_paiement, statut), UNIQUE INDEX UNIQ_PAIEMENT_NUMERO_RECU (numero_recu), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE recu_paiement (id INT AUTO_INCREMENT NOT NULL, numero VARCHAR(60) NOT NULL, pdf_path VARCHAR(255) DEFAULT NULL, qr_payload LONGTEXT DEFAULT NULL, generated_at DATETIME NOT NULL, created_at DATETIME NOT NULL, ecole_id INT NOT NULL, paiement_id INT NOT NULL, INDEX IDX_C56E016077EF1B1E (ecole_id), UNIQUE INDEX UNIQ_C56E01602A4C4478 (paiement_id), UNIQUE INDEX UNIQ_RECU_PAIEMENT_NUMERO (numero), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE regle_frais (id INT AUTO_INCREMENT NOT NULL, montant NUMERIC(12, 2) NOT NULL, periodicite VARCHAR(40) DEFAULT NULL, mois_debut INT DEFAULT NULL, nombre_echeances INT DEFAULT NULL, description LONGTEXT DEFAULT NULL, actif TINYINT DEFAULT 1 NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, ecole_id INT NOT NULL, annee_scolaire_id INT DEFAULT NULL, type_frais_id INT NOT NULL, section_id INT DEFAULT NULL, classe_id INT DEFAULT NULL, INDEX IDX_8275AE9677EF1B1E (ecole_id), INDEX IDX_8275AE969331C741 (annee_scolaire_id), INDEX IDX_8275AE9672AE4A38 (type_frais_id), INDEX IDX_8275AE96D823E37A (section_id), INDEX IDX_8275AE968F5EA509 (classe_id), INDEX IDX_REGLE_FRAIS_SCOPE (ecole_id, annee_scolaire_id, section_id, classe_id, actif), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE type_frais (id INT AUTO_INCREMENT NOT NULL, code VARCHAR(60) NOT NULL, libelle VARCHAR(160) NOT NULL, description LONGTEXT DEFAULT NULL, nature VARCHAR(40) NOT NULL, periodicite VARCHAR(40) DEFAULT NULL, montant_defaut NUMERIC(12, 2) DEFAULT NULL, ordre INT DEFAULT 1 NOT NULL, actif TINYINT DEFAULT 1 NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, ecole_id INT NOT NULL, INDEX IDX_2B4CCB6F77EF1B1E (ecole_id), UNIQUE INDEX UNIQ_TYPE_FRAIS_ECOLE_CODE (ecole_id, code), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('ALTER TABLE categorie_depense ADD CONSTRAINT FK_6B8639F577EF1B1E FOREIGN KEY (ecole_id) REFERENCES ecoles (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE depenses ADD CONSTRAINT FK_EE350ECB77EF1B1E FOREIGN KEY (ecole_id) REFERENCES ecoles (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE depenses ADD CONSTRAINT FK_EE350ECB9331C741 FOREIGN KEY (annee_scolaire_id) REFERENCES annees_scolaires (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE depenses ADD CONSTRAINT FK_EE350ECBBCF5E72D FOREIGN KEY (categorie_id) REFERENCES categorie_depense (id) ON DELETE RESTRICT');
        $this->addSql('ALTER TABLE echeance_paiement ADD CONSTRAINT FK_4E0FB37A77EF1B1E FOREIGN KEY (ecole_id) REFERENCES ecoles (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE echeance_paiement ADD CONSTRAINT FK_4E0FB37ADDEAB1A3 FOREIGN KEY (etudiant_id) REFERENCES etudiants (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE echeance_paiement ADD CONSTRAINT FK_4E0FB37AE677059A FOREIGN KEY (parcours_etudiant_id) REFERENCES parcours_etudiant (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE echeance_paiement ADD CONSTRAINT FK_4E0FB37A9331C741 FOREIGN KEY (annee_scolaire_id) REFERENCES annees_scolaires (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE echeance_paiement ADD CONSTRAINT FK_4E0FB37A72AE4A38 FOREIGN KEY (type_frais_id) REFERENCES type_frais (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE echeance_paiement ADD CONSTRAINT FK_4E0FB37A8F341524 FOREIGN KEY (regle_frais_id) REFERENCES regle_frais (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE ligne_paiement ADD CONSTRAINT FK_EE466B282A4C4478 FOREIGN KEY (paiement_id) REFERENCES paiements (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE ligne_paiement ADD CONSTRAINT FK_EE466B2877EF1B1E FOREIGN KEY (ecole_id) REFERENCES ecoles (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE ligne_paiement ADD CONSTRAINT FK_EE466B286070C812 FOREIGN KEY (echeance_paiement_id) REFERENCES echeance_paiement (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE ligne_paiement ADD CONSTRAINT FK_EE466B28E677059A FOREIGN KEY (parcours_etudiant_id) REFERENCES parcours_etudiant (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE ligne_paiement ADD CONSTRAINT FK_EE466B2872AE4A38 FOREIGN KEY (type_frais_id) REFERENCES type_frais (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE mouvement_caisse ADD CONSTRAINT FK_C8E3DDFE77EF1B1E FOREIGN KEY (ecole_id) REFERENCES ecoles (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE mouvement_caisse ADD CONSTRAINT FK_C8E3DDFE9331C741 FOREIGN KEY (annee_scolaire_id) REFERENCES annees_scolaires (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE mouvement_caisse ADD CONSTRAINT FK_C8E3DDFE2A4C4478 FOREIGN KEY (paiement_id) REFERENCES paiements (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE mouvement_caisse ADD CONSTRAINT FK_C8E3DDFE41D81563 FOREIGN KEY (depense_id) REFERENCES depenses (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE paiements ADD CONSTRAINT FK_E1B02E1277EF1B1E FOREIGN KEY (ecole_id) REFERENCES ecoles (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE paiements ADD CONSTRAINT FK_E1B02E12DDEAB1A3 FOREIGN KEY (etudiant_id) REFERENCES etudiants (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE paiements ADD CONSTRAINT FK_E1B02E129331C741 FOREIGN KEY (annee_scolaire_id) REFERENCES annees_scolaires (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE paiements ADD CONSTRAINT FK_E1B02E125DAC5993 FOREIGN KEY (inscription_id) REFERENCES inscriptions (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE recu_paiement ADD CONSTRAINT FK_C56E016077EF1B1E FOREIGN KEY (ecole_id) REFERENCES ecoles (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE recu_paiement ADD CONSTRAINT FK_C56E01602A4C4478 FOREIGN KEY (paiement_id) REFERENCES paiements (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE regle_frais ADD CONSTRAINT FK_8275AE9677EF1B1E FOREIGN KEY (ecole_id) REFERENCES ecoles (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE regle_frais ADD CONSTRAINT FK_8275AE969331C741 FOREIGN KEY (annee_scolaire_id) REFERENCES annees_scolaires (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE regle_frais ADD CONSTRAINT FK_8275AE9672AE4A38 FOREIGN KEY (type_frais_id) REFERENCES type_frais (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE regle_frais ADD CONSTRAINT FK_8275AE96D823E37A FOREIGN KEY (section_id) REFERENCES sections (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE regle_frais ADD CONSTRAINT FK_8275AE968F5EA509 FOREIGN KEY (classe_id) REFERENCES classes (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE type_frais ADD CONSTRAINT FK_2B4CCB6F77EF1B1E FOREIGN KEY (ecole_id) REFERENCES ecoles (id) ON DELETE CASCADE');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE categorie_depense DROP FOREIGN KEY FK_6B8639F577EF1B1E');
        $this->addSql('ALTER TABLE depenses DROP FOREIGN KEY FK_EE350ECB77EF1B1E');
        $this->addSql('ALTER TABLE depenses DROP FOREIGN KEY FK_EE350ECB9331C741');
        $this->addSql('ALTER TABLE depenses DROP FOREIGN KEY FK_EE350ECBBCF5E72D');
        $this->addSql('ALTER TABLE echeance_paiement DROP FOREIGN KEY FK_4E0FB37A77EF1B1E');
        $this->addSql('ALTER TABLE echeance_paiement DROP FOREIGN KEY FK_4E0FB37ADDEAB1A3');
        $this->addSql('ALTER TABLE echeance_paiement DROP FOREIGN KEY FK_4E0FB37AE677059A');
        $this->addSql('ALTER TABLE echeance_paiement DROP FOREIGN KEY FK_4E0FB37A9331C741');
        $this->addSql('ALTER TABLE echeance_paiement DROP FOREIGN KEY FK_4E0FB37A72AE4A38');
        $this->addSql('ALTER TABLE echeance_paiement DROP FOREIGN KEY FK_4E0FB37A8F341524');
        $this->addSql('ALTER TABLE ligne_paiement DROP FOREIGN KEY FK_EE466B282A4C4478');
        $this->addSql('ALTER TABLE ligne_paiement DROP FOREIGN KEY FK_EE466B2877EF1B1E');
        $this->addSql('ALTER TABLE ligne_paiement DROP FOREIGN KEY FK_EE466B286070C812');
        $this->addSql('ALTER TABLE ligne_paiement DROP FOREIGN KEY FK_EE466B28E677059A');
        $this->addSql('ALTER TABLE ligne_paiement DROP FOREIGN KEY FK_EE466B2872AE4A38');
        $this->addSql('ALTER TABLE mouvement_caisse DROP FOREIGN KEY FK_C8E3DDFE77EF1B1E');
        $this->addSql('ALTER TABLE mouvement_caisse DROP FOREIGN KEY FK_C8E3DDFE9331C741');
        $this->addSql('ALTER TABLE mouvement_caisse DROP FOREIGN KEY FK_C8E3DDFE2A4C4478');
        $this->addSql('ALTER TABLE mouvement_caisse DROP FOREIGN KEY FK_C8E3DDFE41D81563');
        $this->addSql('ALTER TABLE paiements DROP FOREIGN KEY FK_E1B02E1277EF1B1E');
        $this->addSql('ALTER TABLE paiements DROP FOREIGN KEY FK_E1B02E12DDEAB1A3');
        $this->addSql('ALTER TABLE paiements DROP FOREIGN KEY FK_E1B02E129331C741');
        $this->addSql('ALTER TABLE paiements DROP FOREIGN KEY FK_E1B02E125DAC5993');
        $this->addSql('ALTER TABLE recu_paiement DROP FOREIGN KEY FK_C56E016077EF1B1E');
        $this->addSql('ALTER TABLE recu_paiement DROP FOREIGN KEY FK_C56E01602A4C4478');
        $this->addSql('ALTER TABLE regle_frais DROP FOREIGN KEY FK_8275AE9677EF1B1E');
        $this->addSql('ALTER TABLE regle_frais DROP FOREIGN KEY FK_8275AE969331C741');
        $this->addSql('ALTER TABLE regle_frais DROP FOREIGN KEY FK_8275AE9672AE4A38');
        $this->addSql('ALTER TABLE regle_frais DROP FOREIGN KEY FK_8275AE96D823E37A');
        $this->addSql('ALTER TABLE regle_frais DROP FOREIGN KEY FK_8275AE968F5EA509');
        $this->addSql('ALTER TABLE type_frais DROP FOREIGN KEY FK_2B4CCB6F77EF1B1E');
        $this->addSql('DROP TABLE categorie_depense');
        $this->addSql('DROP TABLE depenses');
        $this->addSql('DROP TABLE echeance_paiement');
        $this->addSql('DROP TABLE ligne_paiement');
        $this->addSql('DROP TABLE mouvement_caisse');
        $this->addSql('DROP TABLE paiements');
        $this->addSql('DROP TABLE recu_paiement');
        $this->addSql('DROP TABLE regle_frais');
        $this->addSql('DROP TABLE type_frais');
    }
}
