<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddTransaksiColumns extends Migration
{
    public function up()
    {
        // Peminjaman: tambah bukti_bayar
        $this->forge->addColumn('peminjaman', [
            'bukti_bayar' => [
                'type'       => 'VARCHAR',
                'constraint' => 255,
                'null'       => true,
                'after'      => 'foto',
            ]
        ]);

        // Perbaikan: tambah bukti_bayar
        $this->forge->addColumn('perbaikan', [
            'bukti_bayar' => [
                'type'       => 'VARCHAR',
                'constraint' => 255,
                'null'       => true,
                'after'      => 'foto',
            ]
        ]);

        // Pengajuan: tambah status_realisasi + bukti_bayar
        $this->forge->addColumn('pengajuan', [
            'status_realisasi' => [
                'type'       => 'VARCHAR',
                'constraint' => 50,
                'default'    => 'Pending',
                'null'       => true,
                'after'      => 'keterangan',
            ],
            'bukti_bayar' => [
                'type'       => 'VARCHAR',
                'constraint' => 255,
                'null'       => true,
                'after'      => 'status_realisasi',
            ]
        ]);

        // Penghapusan: tambah status_realisasi, bukti_realisasi, pemasukan
        $this->forge->addColumn('penghapusan', [
            'status_realisasi' => [
                'type'       => 'VARCHAR',
                'constraint' => 50,
                'null'       => true,
                'after'      => 'keterangan',
            ],
            'bukti_realisasi' => [
                'type'       => 'VARCHAR',
                'constraint' => 255,
                'null'       => true,
                'after'      => 'status_realisasi',
            ],
            'pemasukan' => [
                'type'    => 'DOUBLE',
                'default' => 0,
                'null'    => true,
                'after'   => 'bukti_realisasi',
            ]
        ]);
    }

    public function down()
    {
        $this->forge->dropColumn('peminjaman', 'bukti_bayar');
        $this->forge->dropColumn('perbaikan', 'bukti_bayar');
        $this->forge->dropColumn('pengajuan', ['status_realisasi', 'bukti_bayar']);
        $this->forge->dropColumn('penghapusan', ['status_realisasi', 'bukti_realisasi', 'pemasukan']);
    }
}
