<?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('sc_role_screen_permissions', function (Blueprint $blueprint) {
            $blueprint->id();
            $blueprint->unsignedBigInteger('fk_role');
            $blueprint->unsignedBigInteger('fk_office');
            $blueprint->boolean('create')->default(false);
            $blueprint->boolean('update')->default(false);
            $blueprint->boolean('delete')->default(false);
            $blueprint->boolean('restore')->default(false);
            $blueprint->boolean('show')->default(false);
            $blueprint->boolean('download')->default(false);
            $blueprint->boolean('export')->default(false);
            $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_role')->references('id')->on('sc_roles');
            $blueprint->foreign('fk_office')->references('id')->on('sy_offices');
            $blueprint->foreign('fk_usercreator')->references('id')->on('sc_users');
            $blueprint->foreign('fk_userupdater')->references('id')->on('sc_users');
        });
    }

    public function down(): void
    {
        Schema::dropDatabaseIfExists('sc_role_screen_permissions');
    }
};
