<?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_types');

    } // down()


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

        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('brand', 50);
                $Table->json('config_template');
                $Table->string('description', 255)->nullable();
                $Table->string('endpoint_prefix', 50)->nullable();
                $Table->string('identifier', 50);
                $Table->string('label', 100);
                $Table->string('model', 50);
                $Table->json('payload_template');

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

                new CodeGenerator($Table, [
                    'columns' => [
                        'id' => [
                            'gridField' => 1,
                        ],
                        'brand' => [
                            'gridField'   => 2,
                            'searchField' => true,
                            'sortable'    => true,
                        ],
                        'config_template' => [
                            'jsonType' => CodeGenerator::JSON_TYPE_OBJECT,
                        ],
                        'endpoint_prefix' => [],
                        'identifier' => [
                            'searchField' => true,
                            'sortable'    => true,
                        ],
                        'label' => [
                            'gridField'   => 4,
                            'searchField' => true,
                            'sortable'    => SortContext::Grid->value,
                        ],
                        'model' => [
                            'gridField'   => 3,
                            'searchField' => true,
                            'sortable'    => true,
                        ],
                        'payload_template' => [
                            'jsonType' => CodeGenerator::JSON_TYPE_OBJECT,
                        ],
                    ],
                ]);

            });
        }
    } // up()

};
