<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260225211435 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create teacher_import_batches and saved_teacher_column_mappings tables for CSV/XLSX teacher import wizard';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE TABLE teacher_import_batches (
            id UUID NOT NULL,
            tenant_id UUID NOT NULL,
            original_filename VARCHAR(255) NOT NULL,
            total_rows INT NOT NULL DEFAULT 0,
            detected_columns JSONB NOT NULL DEFAULT \'[]\',
            detected_format VARCHAR(50) DEFAULT NULL,
            status VARCHAR(20) NOT NULL DEFAULT \'pending\',
            mapping_data JSONB DEFAULT NULL,
            imported_count INT NOT NULL DEFAULT 0,
            error_count INT NOT NULL DEFAULT 0,
            rows_data JSONB NOT NULL DEFAULT \'[]\',
            created_at TIMESTAMPTZ NOT NULL,
            completed_at TIMESTAMPTZ DEFAULT NULL,
            PRIMARY KEY (id)
        )');

        $this->addSql('CREATE INDEX idx_teacher_import_batches_tenant ON teacher_import_batches (tenant_id)');
        $this->addSql('CREATE INDEX idx_teacher_import_batches_status ON teacher_import_batches (status)');

        $this->addSql('CREATE TABLE saved_teacher_column_mappings (
            tenant_id UUID NOT NULL,
            format VARCHAR(50) NOT NULL,
            mapping_data JSONB NOT NULL,
            saved_at TIMESTAMPTZ NOT NULL,
            PRIMARY KEY (tenant_id, format)
        )');
    }

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