<?php
namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddTransactionIdToSubscriptions extends Migration
{
    public function up()
    {
        $fields = [
            'transaction_id' => [
                'type' => 'VARCHAR',
                'constraint' => 50,
                'null' => true,
                'after' => 'plan_id',
            ],
        ];
        $this->forge->addColumn('subscriptions', $fields);
    }

    public function down()
    {
        $this->forge->dropColumn('subscriptions', 'transaction_id');
    }
}

class AddStatusCheckAttemptsToTransactions extends Migration
{
    public function up()
    {
        if (!$this->db->fieldExists('status_check_attempts', 'transactions')) {
            $this->forge->addColumn('transactions', [
                'status_check_attempts' => [
                    'type' => 'INT',
                    'constraint' => 1,
                    'default' => 0,
                    'after' => 'status',
                ],
            ]);
        }
    }

    public function down()
    {
        if ($this->db->fieldExists('status_check_attempts', 'transactions')) {
            $this->forge->dropColumn('transactions', 'status_check_attempts');
        }
    }
}

class AddPlanIdToTransactions extends Migration
{
    public function up()
    {
        if (!$this->db->fieldExists('plan_id', 'transactions')) {
            $this->forge->addColumn('transactions', [
                'plan_id' => [
                    'type' => 'INT',
                    'constraint' => 11,
                    'null' => true,
                    'after' => 'tip_id',
                ],
            ]);
        }
    }

    public function down()
    {
        if ($this->db->fieldExists('plan_id', 'transactions')) {
            $this->forge->dropColumn('transactions', 'plan_id');
        }
    }
} 