<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260125170000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Add audit_logs table to store per-entity history entries.';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            CREATE TABLE audit_logs (
                id VARCHAR(36) NOT NULL,
                entityType VARCHAR(50) NOT NULL,
                entityId VARCHAR(36) NOT NULL,
                action VARCHAR(20) NOT NULL,
                diff JSON DEFAULT NULL,
                snapshot JSON DEFAULT NULL,
                actorProfileId VARCHAR(36) DEFAULT NULL,
                createdAt TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                PRIMARY KEY(id)
            )
        SQL);

        $this->addSql('CREATE INDEX idx_audit_entity ON audit_logs (entityType, entityId)');
        $this->addSql('CREATE INDEX idx_audit_created_at ON audit_logs (createdAt)');
    }

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