<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
 * Secretary share of an online appointment: the total on the payment's financial
 * breakdown, plus one row per secretary so the panel can report per user.
 */
final class Version20260725144018 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Add secretary_earnings and financial_breakdowns.secretary_share_rials';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE TABLE secretary_earnings (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, relation_uuid VARCHAR(36) NOT NULL, share_percent NUMERIC(5, 2) NOT NULL, share_rials INT NOT NULL, created_at INT NOT NULL, breakdown_id INT NOT NULL, secretary_user_id INT NOT NULL, UNIQUE INDEX UNIQ_8F257C76D17F50A6 (uuid), INDEX IDX_8F257C7667F54C40 (breakdown_id), INDEX IDX_8F257C7658E93B3D (secretary_user_id), INDEX idx_secretary_earnings_user_time (secretary_user_id, created_at), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('ALTER TABLE secretary_earnings ADD CONSTRAINT FK_8F257C7667F54C40 FOREIGN KEY (breakdown_id) REFERENCES financial_breakdowns (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE secretary_earnings ADD CONSTRAINT FK_8F257C7658E93B3D FOREIGN KEY (secretary_user_id) REFERENCES users (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE financial_breakdowns ADD secretary_share_rials INT DEFAULT 0 NOT NULL');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE secretary_earnings DROP FOREIGN KEY FK_8F257C7667F54C40');
        $this->addSql('ALTER TABLE secretary_earnings DROP FOREIGN KEY FK_8F257C7658E93B3D');
        $this->addSql('DROP TABLE secretary_earnings');
        $this->addSql('ALTER TABLE financial_breakdowns DROP secretary_share_rials');
    }
}
