<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
 * تاریخچه‌ی تغییرات خدمات — هم‌شکل session_audit_logs.
 */
final class Version20260718084524 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Add service_item_audit_logs table';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE TABLE service_item_audit_logs (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, field VARCHAR(40) NOT NULL, operation VARCHAR(10) NOT NULL, old_value LONGTEXT DEFAULT NULL, new_value LONGTEXT DEFAULT NULL, actor_user_id INT DEFAULT NULL, actor_name VARCHAR(191) DEFAULT NULL, created_at INT NOT NULL, service_item_id INT NOT NULL, UNIQUE INDEX UNIQ_499F70B6D17F50A6 (uuid), INDEX IDX_499F70B6DDEB00C2 (service_item_id), INDEX idx_service_item_audit_item (service_item_id, created_at), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('ALTER TABLE service_item_audit_logs ADD CONSTRAINT FK_499F70B6DDEB00C2 FOREIGN KEY (service_item_id) REFERENCES service_items (id) ON DELETE CASCADE');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE service_item_audit_logs DROP FOREIGN KEY FK_499F70B6DDEB00C2');
        $this->addSql('DROP TABLE service_item_audit_logs');
    }
}
