<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('sy_guarantees', function (Blueprint $blueprint) {
            $blueprint->id();
            $blueprint->unsignedBigInteger('fk_loan');
            $blueprint->unsignedBigInteger('fk_client');
            $blueprint->unsignedBigInteger('fk_model')->nullable();
            $blueprint->string('description', 255);
            $blueprint->string('serialnumber', 50)->nullable();
            $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_loan')->references('id')->on('sy_loans');
            $blueprint->foreign('fk_client')->references('id')->on('sy_clients');
            $blueprint->foreign('fk_usercreator')->references('id')->on('sc_users');
            $blueprint->foreign('fk_userupdater')->references('id')->on('sc_users');
        });
    }

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