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


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


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


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

    } // down()


    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Logger::reset();

        Schema::create('settings', function (Blueprint $Table) {
            $Table->id();
            $Table->uuid('uuid');

            $Table->timestamps();

            $Table->string('context', 255);
            $Table->boolean('crypted')->default(0);
            $Table->string('key', 50);
            $Table->text('value')->nullable();
            // $Table->unsignedInteger('tenant_id')->nullable();

            $Table->index('context', 'settings_IDX_context');
            $Table->index('key',     'settings_IDX_key');
            // $Table->index('tenant_id', 'settings_IDX_tenant_id');

            new CodeGenerator($Table, [
                'exclude' => [
                    'laravel.*',
                    'livewire.*',
                ],

                'traits' => [
                    'laravel.model' => [
                        'BplanBase\\Globals\\Traits\\HasOrderedScope',
                    ],
                ],
            ]);

        });

    } // up()

};
