<?php

namespace Modules\Ticket\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddOnlineCancellationRefundTracking extends Migration
{
    public function up()
    {
        if (! $this->db->fieldExists('refund_sent_by', 'cancels')) {
            $this->forge->addColumn('cancels', [
                'refund_sent_by' => [
                    'type'       => 'INT',
                    'constraint' => 11,
                    'unsigned'   => true,
                    'null'       => true,
                ],
                'refund_sent_at' => [
                    'type' => 'DATETIME',
                    'null' => true,
                ],
                'refund_note' => [
                    'type' => 'TEXT',
                    'null' => true,
                ],
            ]);
        }
    }

    public function down()
    {
        if ($this->db->fieldExists('refund_sent_by', 'cancels')) {
            $this->forge->dropColumn('cancels', ['refund_sent_by', 'refund_sent_at', 'refund_note']);
        }
    }
}
