<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260323114411 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create evaluations table';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE TABLE evaluations (
            id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
            tenant_id UUID NOT NULL,
            class_id UUID NOT NULL REFERENCES school_classes(id),
            subject_id UUID NOT NULL REFERENCES subjects(id),
            teacher_id UUID NOT NULL REFERENCES users(id),
            title VARCHAR(255) NOT NULL,
            description TEXT,
            evaluation_date DATE NOT NULL,
            grade_scale SMALLINT NOT NULL DEFAULT 20,
            coefficient DECIMAL(3,1) NOT NULL DEFAULT 1.0,
            status VARCHAR(20) NOT NULL DEFAULT \'published\',
            created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
            updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
        )');

        $this->addSql('CREATE INDEX idx_evaluations_tenant ON evaluations(tenant_id)');
        $this->addSql('CREATE INDEX idx_evaluations_class ON evaluations(class_id)');
        $this->addSql('CREATE INDEX idx_evaluations_teacher ON evaluations(teacher_id)');
        $this->addSql('CREATE INDEX idx_evaluations_date ON evaluations(evaluation_date)');
    }

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