<?php
/**
 * Migration Class
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @package     bplan-base/globals
 * @subpackage  Migrations
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 * @copyright   Copyright (C) 2025, 2026 bplan-solutions GmbH & Co. KG <https://www.bplan-solutions.de/>
 * /Δ\
 */


use BplanBase\CodeGenerator\Loaders\CodeGenerator;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;


/**
 * Migration Class
 *
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
return new class extends Migration
{

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('permissions');

    } // down()


    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $tableName = 'permissions';

        if (Schema::hasTable($tableName) === false) {
            Schema::create($tableName, function (Blueprint $Table) {
                $Table->id();
                $Table->uuid('uuid');

                $Table->timestamp('created_at');
                $Table->timestamp('updated_at');

                $Table->string('guard_name', 125)->default('web');
                $Table->string('name', 125);
                $Table->string('package', 60);

                new CodeGenerator($Table, [
                    'columns' => [
                        'name' => [
                            'sortable' => true,
                        ],
                        'package' => [
                            'sortable' => true,
                        ],
                    ],
                    'exclude' => [
                        'laravel.permission-seeder',
                    ],
                    'extends' => [
                        'laravel.model' => 'Spatie\\Permission\\Models\\Permission as BasePermission',
                    ],
                    'routing' => [
                        'terminal' => 'readOnly',
                    ],

                ]);

            });

        }
    } // up()

};
