<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260313080007 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'RTT redesign: split opening_minutes and minutes+rate into 4 fields (base25, bonus25, base50, bonus50)';
    }

    public function up(Schema $schema): void
    {
        // employee_rtt_balances: replace opening_minutes with 4 fields
        $this->addSql('ALTER TABLE employee_rtt_balances ADD opening_base25_minutes INT DEFAULT 0 NOT NULL');
        $this->addSql('ALTER TABLE employee_rtt_balances ADD opening_bonus25_minutes INT DEFAULT 0 NOT NULL');
        $this->addSql('ALTER TABLE employee_rtt_balances ADD opening_base50_minutes INT DEFAULT 0 NOT NULL');
        $this->addSql('ALTER TABLE employee_rtt_balances ADD opening_bonus50_minutes INT DEFAULT 0 NOT NULL');
        $this->addSql('ALTER TABLE employee_rtt_balances DROP opening_minutes');

        // employee_rtt_payments: replace minutes+rate with 4 fields
        $this->addSql('DROP INDEX IF EXISTS uniq_rtt_payment_employee_year_month_rate');
        $this->addSql('ALTER TABLE employee_rtt_payments ADD base25_minutes INT DEFAULT 0 NOT NULL');
        $this->addSql('ALTER TABLE employee_rtt_payments ADD bonus25_minutes INT DEFAULT 0 NOT NULL');
        $this->addSql('ALTER TABLE employee_rtt_payments ADD base50_minutes INT DEFAULT 0 NOT NULL');
        $this->addSql('ALTER TABLE employee_rtt_payments ADD bonus50_minutes INT DEFAULT 0 NOT NULL');
        $this->addSql('ALTER TABLE employee_rtt_payments DROP minutes');
        $this->addSql('ALTER TABLE employee_rtt_payments DROP rate');
    }

    public function down(Schema $schema): void
    {
        // employee_rtt_balances: restore opening_minutes
        $this->addSql('ALTER TABLE employee_rtt_balances ADD opening_minutes INT NOT NULL DEFAULT 0');
        $this->addSql('ALTER TABLE employee_rtt_balances DROP opening_base25_minutes');
        $this->addSql('ALTER TABLE employee_rtt_balances DROP opening_bonus25_minutes');
        $this->addSql('ALTER TABLE employee_rtt_balances DROP opening_base50_minutes');
        $this->addSql('ALTER TABLE employee_rtt_balances DROP opening_bonus50_minutes');

        // employee_rtt_payments: restore minutes+rate
        $this->addSql('ALTER TABLE employee_rtt_payments ADD minutes INT NOT NULL DEFAULT 0');
        $this->addSql("ALTER TABLE employee_rtt_payments ADD rate VARCHAR(10) NOT NULL DEFAULT '25'");
        $this->addSql('ALTER TABLE employee_rtt_payments DROP base25_minutes');
        $this->addSql('ALTER TABLE employee_rtt_payments DROP bonus25_minutes');
        $this->addSql('ALTER TABLE employee_rtt_payments DROP base50_minutes');
        $this->addSql('ALTER TABLE employee_rtt_payments DROP bonus50_minutes');
        $this->addSql('CREATE UNIQUE INDEX uniq_rtt_payment_employee_year_month_rate ON employee_rtt_payments (employee_id, year, month, rate)');
    }
}
