<?php
/**
 * Migration Class
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @package     bplan-modules/visitor-management
 * @subpackage  Migrations
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @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      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('global_settings');

    } // down()


    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('global_settings', function (Blueprint $Table) {
            $Table->foreignId('id')->constrained(table: 'tenants', indexName: 'global_settings_PK');
            $Table->uuid('uuid');

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

            $Table->unsignedInteger('anonymization_threshold_days')->default(30)->comment('Zeitraum in Tagen für Datenanonymisierung.');

            $Table->unique('id',   'global_settings_UKI_id');
            $Table->unique('uuid', 'global_settings_UKI_uuid');

            new CodeGenerator($Table, [
                'columns' => [
                    'id' => [
                        'guarded' => true,
                        'relationName' => 'tenant',
                        'reverseRelationType' => 'HasOne',
                    ],
                ],
                'exclude' => [
                    'laravel.action.create',
                    'laravel.action.delete',
                ],
                'extends' => [
                    'laravel.repository' => 'BplanBase\\Globals\\Foundation\\Repositories\\BaseSettingRepository',
                ],

            ]);

        });

    } // up()

};
