<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddPaymentAndExtendedStatuses extends Migration
{
    public function up()
    {
        // 1. Alter status column in orders table to VARCHAR(50)
        $this->forge->modifyColumn('orders', [
            'status' => [
                'type'       => 'VARCHAR',
                'constraint' => '50',
                'default'    => 'PENDING_PAYMENT',
            ],
        ]);

        // 2. Add payment_methods column to koperasi table
        $this->forge->addColumn('koperasi', [
            'payment_methods' => [
                'type'       => 'VARCHAR',
                'constraint' => '255',
                'default'    => 'qris,transfer_bank,bri,bni,mandiri,bsi',
                'null'       => true,
            ],
        ]);

        // 3. Add payment_method column to orders table
        $this->forge->addColumn('orders', [
            'payment_method' => [
                'type'       => 'VARCHAR',
                'constraint' => '50',
                'default'    => 'saldo',
                'null'       => true,
            ],
        ]);
    }

    public function down()
    {
        // 1. Restore orders status to ENUM
        $this->forge->modifyColumn('orders', [
            'status' => [
                'type'       => 'ENUM',
                'constraint' => ['pending', 'paid', 'processing', 'shipped', 'completed', 'cancelled'],
                'default'    => 'pending',
            ],
        ]);

        // 2. Remove columns
        $this->forge->dropColumn('koperasi', 'payment_methods');
        $this->forge->dropColumn('orders', 'payment_method');
    }
}
