<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Bridge\Doctrine\Migrations;

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

final class Version20260721133300 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Ajoute l historique persistant et les statistiques des imports de la base clients.';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            CREATE TABLE user_imported_client_import (
                id UUID NOT NULL,
                original_filename VARCHAR(255) NOT NULL,
                stored_filename VARCHAR(255) NOT NULL,
                content_type VARCHAR(127) DEFAULT NULL,
                file_size INT NOT NULL,
                total_rows INT NOT NULL,
                created_count INT NOT NULL,
                updated_count INT NOT NULL,
                unchanged_count INT NOT NULL,
                ignored_count INT NOT NULL,
                duplicate_count INT NOT NULL,
                invalid_email_count INT NOT NULL,
                missing_group_count INT NOT NULL,
                group_summary JSON NOT NULL,
                created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                PRIMARY KEY(id)
            )
            SQL);
        $this->addSql('CREATE UNIQUE INDEX UNIQ_399E71C3DF8EB9B7 ON user_imported_client_import (stored_filename)');
        $this->addSql("COMMENT ON COLUMN user_imported_client_import.id IS '(DC2Type:uuid)'");
        $this->addSql("COMMENT ON COLUMN user_imported_client_import.created_at IS '(DC2Type:datetime_immutable)'");
        $this->addSql("COMMENT ON COLUMN user_imported_client_import.updated_at IS '(DC2Type:datetime_immutable)'");
    }

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