<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('debitures', function (Blueprint $table) {
            // nullable
            $table->string('cif', 16)
            ->nullable()
            ->default('0000000000')
            ->comment('asal data LPJ.PRM_DEBITUR.KODE_CIF. Pada KODE_CIF ada yang digitnya 16 => 3372040405810002')
            ->change();
            $table->unsignedBigInteger('branch_id')->nullable()->change();
            $table->string('nomor_id', 50)->nullable()->change();

            $table->unsignedBigInteger('mig_kd_debitur_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR.KD_DEBITUR_SEQ. Berguna untuk update debitur_id menggunakan KD_DEBITUR_SEQ nya');
            $table->timestamp('processed_at')->nullable();
            $table->char('is_mig', 1)->nullable()->comment('untuk menandakan row ini dari LPJ OLD');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('debitures', function (Blueprint $table) {
            // Kembalikan kolom branch_id agar tidak nullable (asumsi awal NOT NULL)
            $table->unsignedBigInteger('branch_id')->nullable(false)->change();

            // Kembalikan kolom yang diubah nullable menjadi NOT NULL
            $table->string('cif', 10)->nullable(false)->change();
            $table->string('nomor_id', 50)->nullable(false)->change();

            // Hapus kolom tambahan yang dibuat di up()
            $table->dropColumn([
                'mig_kd_debitur_seq',
                'mig_urut_seq_addr',
                'mig_urut_seq_comm',
                'processed_at',
                'is_mig'
            ]);
        });
    }
};
