<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20260728080123 extends AbstractMigration
{
    /**
     * Phase 3 of the tenant-marking series: discount_rules spelled the tenant as
     * owner_type/owner_id, which the Doctrine filter added in phase 4 would not
     * recognise. Pure rename — no data moves, so CHANGE is enough.
     */
    public function getDescription(): string
    {
        return 'Rename discount_rules owner_type/owner_id to the shared entity_type/entity_id pair';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('DROP INDEX idx_discount_rules_owner ON discount_rules');
        $this->addSql('ALTER TABLE discount_rules CHANGE owner_type entity_type VARCHAR(10) NOT NULL, CHANGE owner_id entity_id INT NOT NULL');
        $this->addSql('CREATE INDEX idx_discount_rules_tenant ON discount_rules (entity_type, entity_id, active)');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP INDEX idx_discount_rules_tenant ON discount_rules');
        $this->addSql('ALTER TABLE discount_rules CHANGE entity_type owner_type VARCHAR(10) NOT NULL, CHANGE entity_id owner_id INT NOT NULL');
        $this->addSql('CREATE INDEX idx_discount_rules_owner ON discount_rules (owner_type, owner_id, active)');
    }
}
