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

    } // down()


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

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

                $Table->timestamp('created_at');

                $Table->foreignId('location_id')->constrained(table: 'locations', indexName: 'location_printer_FK_location_id')->restrictOnDelete();
                $Table->foreignId('printer_id')->constrained(table: 'printers', indexName: 'location_printer_FK_printer_id')->cascadeOnDelete();

                $Table->index('location_id', 'location_printer_FKI_location_id');
                $Table->index('printer_id',  'location_printer_FKI_printer_id');
                $Table->unique('uuid',       'location_printer_UKI_uuid');

                new CodeGenerator($Table, [
                    'exclude' => [
                        'laravel.action.update',
                        'laravel.permission-seeder',
                        'livewire.*',
                    ],
                    'pivot' => [
                        'relations' => [
                            'location_id' => 'locations',
                            'printer_id'  => 'printers',
                        ],
                    ],
                    'routing' => [
                        'terminal' => 'readOnly',
                    ],

                ]);

            });
        }
    } // up()


};
