<?php

namespace Tenant\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * Real refund support — shown repeatedly across a user-supplied mockup
 * batch (Payments, Folio Details all included a refund flow), and unlike
 * "AI Modules" this is genuinely buildable for real with modest effort:
 * a refund is just a folio_payments row like any other, flagged
 * `is_refund`, subtracted instead of added when computing what's been
 * paid (see FolioModel::totalPaid()). No separate refunds table, no new
 * payment-method concept — refunds reuse the exact same ledger.
 */
class AddIsRefundToFolioPayments extends Migration
{
    public function up()
    {
        $this->forge->addColumn('folio_payments', [
            'is_refund' => [
                'type'       => 'TINYINT',
                'constraint' => 1,
                'default'    => 0,
                'after'      => 'amount',
            ],
            'refund_reason' => [
                'type'       => 'VARCHAR',
                'constraint' => 255,
                'null'       => true,
                'after'      => 'is_refund',
            ],
        ]);
    }

    public function down()
    {
        $this->forge->dropColumn('folio_payments', ['is_refund', 'refund_reason']);
    }
}
