<?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 Version20260716094319 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Session settlement: session_payments table + discount/paid_at columns on patient_sessions';
    }

    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE TABLE session_payments (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, method VARCHAR(15) NOT NULL, amount_rials INT NOT NULL, paid_at INT NOT NULL, created_by_name VARCHAR(255) DEFAULT NULL, created_at INT NOT NULL, session_id INT NOT NULL, created_by_id INT DEFAULT NULL, UNIQUE INDEX UNIQ_EE7EFB5AD17F50A6 (uuid), INDEX IDX_EE7EFB5A613FECDF (session_id), INDEX IDX_EE7EFB5AB03A8386 (created_by_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
        $this->addSql('ALTER TABLE session_payments ADD CONSTRAINT FK_EE7EFB5A613FECDF FOREIGN KEY (session_id) REFERENCES patient_sessions (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE session_payments ADD CONSTRAINT FK_EE7EFB5AB03A8386 FOREIGN KEY (created_by_id) REFERENCES users (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE patient_sessions ADD discount_type VARCHAR(10) DEFAULT NULL, ADD discount_value INT DEFAULT 0 NOT NULL, ADD discount_rials INT DEFAULT 0 NOT NULL, ADD paid_at INT DEFAULT NULL');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE session_payments DROP FOREIGN KEY FK_EE7EFB5A613FECDF');
        $this->addSql('ALTER TABLE session_payments DROP FOREIGN KEY FK_EE7EFB5AB03A8386');
        $this->addSql('DROP TABLE session_payments');
        $this->addSql('ALTER TABLE patient_sessions DROP discount_type, DROP discount_value, DROP discount_rials, DROP paid_at');
    }
}
