<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
 * Migration pour créer la table school_grading_configurations.
 *
 * @see FR24 - Supporter différentes pédagogies
 */
final class Version20260206100000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create school_grading_configurations table for grading mode management';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            CREATE TABLE school_grading_configurations (
                id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
                tenant_id UUID NOT NULL,
                school_id UUID NOT NULL,
                academic_year_id UUID NOT NULL,
                grading_mode VARCHAR(20) NOT NULL DEFAULT 'numeric_20' CHECK (grading_mode IN ('numeric_20', 'numeric_10', 'letters', 'competencies', 'no_grades')),
                configured_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
                updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
            )
        SQL);

        $this->addSql('CREATE INDEX idx_grading_config_tenant_id ON school_grading_configurations(tenant_id)');
        $this->addSql(<<<'SQL'
            CREATE UNIQUE INDEX idx_grading_config_unique
            ON school_grading_configurations (tenant_id, school_id, academic_year_id)
        SQL);
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP TABLE IF EXISTS school_grading_configurations');
    }
}
