<?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 Version20260426192950 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create themes and schools, then link school admins to their madrassa';
    }

    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE TABLE ecoles (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(180) NOT NULL, slug VARCHAR(120) NOT NULL, sous_domaine VARCHAR(120) NOT NULL, prefixe_matricule VARCHAR(12) NOT NULL, dernier_numero_matricule INT DEFAULT 0 NOT NULL, logo VARCHAR(255) DEFAULT NULL, description LONGTEXT DEFAULT NULL, slogan VARCHAR(255) DEFAULT NULL, email VARCHAR(180) DEFAULT NULL, telephone1 VARCHAR(30) DEFAULT NULL, telephone2 VARCHAR(30) DEFAULT NULL, whatsapp VARCHAR(30) DEFAULT NULL, adresse VARCHAR(255) DEFAULT NULL, ville VARCHAR(120) DEFAULT NULL, pays VARCHAR(120) DEFAULT NULL, couleur_principale VARCHAR(20) DEFAULT NULL, couleur_secondaire VARCHAR(20) DEFAULT NULL, couleur_accent VARCHAR(20) DEFAULT NULL, hero_title VARCHAR(255) DEFAULT NULL, hero_subtitle LONGTEXT DEFAULT NULL, about_title VARCHAR(255) DEFAULT NULL, about_text LONGTEXT DEFAULT NULL, cta_title VARCHAR(255) DEFAULT NULL, cta_text LONGTEXT DEFAULT NULL, active TINYINT DEFAULT 1 NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, theme_public_id INT DEFAULT NULL, UNIQUE INDEX UNIQ_C46758A2989D9B62 (slug), UNIQUE INDEX UNIQ_C46758A25BA67281 (sous_domaine), INDEX IDX_C46758A27B77511C (theme_public_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('CREATE TABLE themes (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(120) NOT NULL, code VARCHAR(80) NOT NULL, description LONGTEXT DEFAULT NULL, preview_image VARCHAR(255) DEFAULT NULL, actif TINYINT DEFAULT 1 NOT NULL, created_at DATETIME NOT NULL, UNIQUE INDEX UNIQ_154232DE77153098 (code), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('ALTER TABLE ecoles ADD CONSTRAINT FK_C46758A27B77511C FOREIGN KEY (theme_public_id) REFERENCES themes (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE users ADD ecole_id INT DEFAULT NULL, CHANGE roles roles JSON NOT NULL, CHANGE created_at created_at DATETIME NOT NULL, CHANGE updated_at updated_at DATETIME NOT NULL');
        $this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E977EF1B1E FOREIGN KEY (ecole_id) REFERENCES ecoles (id) ON DELETE SET NULL');
        $this->addSql('CREATE INDEX IDX_1483A5E977EF1B1E ON users (ecole_id)');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE users DROP FOREIGN KEY FK_1483A5E977EF1B1E');
        $this->addSql('DROP INDEX IDX_1483A5E977EF1B1E ON users');
        $this->addSql('ALTER TABLE ecoles DROP FOREIGN KEY FK_C46758A27B77511C');
        $this->addSql('DROP TABLE ecoles');
        $this->addSql('DROP TABLE themes');
        $this->addSql('ALTER TABLE users DROP ecole_id, CHANGE roles roles LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\', CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
    }
}
