<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('ct_status_types', function (Blueprint $blueprint) {
            $blueprint->id();
            $blueprint->string('statustypename', 30);
            $blueprint->boolean('visible')->default(true);
            $blueprint->boolean('available')->default(true);
            $blueprint->unsignedBigInteger('fk_usercreator')->nullable();
            $blueprint->timestamp('created_at')->useCurrent();
            $blueprint->unsignedBigInteger('fk_userupdater')->nullable();
            $blueprint->timestamp('updated_at')->useCurrentOnUpdate()->nullable();
            $blueprint->boolean('is_active')->default(true);

            $blueprint->foreign('fk_usercreator')->references('id')->on('sc_users');
            $blueprint->foreign('fk_userupdater')->references('id')->on('sc_users');
        });

        DB::table('ct_status_types')->insert([
            ['statustypename' => 'CLIENTS', 'fk_usercreator' => 1],
            ['statustypename' => 'ENDORSEMENTS', 'fk_usercreator' => 1],
            ['statustypename' => 'LOANS', 'fk_usercreator' => 1],
            ['statustypename' => 'PAYMENTS', 'fk_usercreator' => 1],
            ['statustypename' => 'BEHAVIOR', 'fk_usercreator' => 1],
        ]);
    }

    public function down(): void
    {
        Schema::dropIfExists('ct_status_types');
    }
};
