<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260331154510 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Ajout des appréciations sur les notes et table des modèles d\'appréciations enseignant';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            ALTER TABLE grades ADD COLUMN appreciation TEXT
            SQL);

        $this->addSql(<<<'SQL'
            ALTER TABLE grades ADD COLUMN appreciation_updated_at TIMESTAMPTZ
            SQL);

        $this->addSql(<<<'SQL'
            CREATE TABLE appreciation_templates (
                id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
                tenant_id UUID NOT NULL,
                teacher_id UUID NOT NULL REFERENCES users(id),
                title VARCHAR(100) NOT NULL,
                content TEXT NOT NULL,
                category VARCHAR(50),
                usage_count INT NOT NULL DEFAULT 0,
                created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
                updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
            )
            SQL);

        $this->addSql(<<<'SQL'
            CREATE INDEX idx_templates_teacher ON appreciation_templates(teacher_id)
            SQL);

        $this->addSql(<<<'SQL'
            CREATE INDEX idx_templates_tenant ON appreciation_templates(tenant_id)
            SQL);
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP TABLE IF EXISTS appreciation_templates');
        $this->addSql('ALTER TABLE grades DROP COLUMN IF EXISTS appreciation_updated_at');
        $this->addSql('ALTER TABLE grades DROP COLUMN IF EXISTS appreciation');
    }
}
