<?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\Enums\SortContext;
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('printer_hosts');

    } // down()


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

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

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

                $Table->string('api_key', 255);
                $Table->string('host', 255);
                $Table->string('identifier', 50);

                $Table->unique('identifier', 'printer_hosts_UKI_identifier');

                new CodeGenerator($Table, [
                    'columns' => [
                        'id' => [
                            'gridField' => 1,
                        ],
                        'identifier' => [
                            'gridField'   => 3,
                            'searchField' => true,
                            'sortable'    => SortContext::Grid->value,
                        ],
                        'host' => [
                            'gridField'   => 2,
                            'searchField' => true,
                            'sortable'    => SortContext::Grid->value,
                        ],
                    ],
                    'exclude' => [
                        //'laravel.permission-seeder',
                    ],
                ]);

            });
        }
    } // up()

};
