<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $sql = <<<'SQL'
            CREATE TABLE sticker_mapping_masters (
                id                          BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
                plant_id                    BIGINT NOT NULL,
                item_characteristic_id      BIGINT DEFAULT NULL,
                sticker_structure1_id       BIGINT DEFAULT NULL,
                sticker1_machine_id         BIGINT DEFAULT NULL,
                sticker1_print_ip           TEXT DEFAULT NULL,

                sticker_structure2_id       BIGINT DEFAULT NULL,
                sticker2_machine_id         BIGINT DEFAULT NULL,
                sticker2_print_ip           TEXT DEFAULT NULL,

                sticker_structure3_id       BIGINT DEFAULT NULL,
                sticker3_machine_id         BIGINT DEFAULT NULL,
                sticker3_print_ip           TEXT DEFAULT NULL,

                sticker_structure4_id       BIGINT DEFAULT NULL,
                sticker4_machine_id         BIGINT DEFAULT NULL,
                sticker4_print_ip           TEXT DEFAULT NULL,

                sticker_structure5_id       BIGINT DEFAULT NULL,
                sticker5_machine_id         BIGINT DEFAULT NULL,
                sticker5_print_ip           TEXT DEFAULT NULL,

                sticker_structure6_id       BIGINT DEFAULT NULL,
                sticker6_machine_id         BIGINT DEFAULT NULL,
                sticker6_print_ip           TEXT DEFAULT NULL,

                sticker_structure7_id       BIGINT DEFAULT NULL,
                sticker7_machine_id         BIGINT DEFAULT NULL,
                sticker7_print_ip           TEXT DEFAULT NULL,

                sticker_structure8_id       BIGINT DEFAULT NULL,
                sticker8_machine_id         BIGINT DEFAULT NULL,
                sticker8_print_ip           TEXT DEFAULT NULL,

                created_at                  TIMESTAMP NOT NULL DEFAULT NOW(),
                updated_at                  TIMESTAMP NOT NULL DEFAULT NOW(),
                created_by                  TEXT DEFAULT NULL,
                updated_by                  TEXT DEFAULT NULL,
                deleted_at                  TIMESTAMP,

                FOREIGN KEY (plant_id) REFERENCES plants(id),
                FOREIGN KEY (item_characteristic_id) REFERENCES item_characteristics(id),

                FOREIGN KEY (sticker_structure1_id) REFERENCES sticker_structure_details(id),
                FOREIGN KEY (sticker_structure2_id) REFERENCES sticker_structure_details(id),
                FOREIGN KEY (sticker_structure3_id) REFERENCES sticker_structure_details(id),
                FOREIGN KEY (sticker_structure4_id) REFERENCES sticker_structure_details(id),
                FOREIGN KEY (sticker_structure5_id) REFERENCES sticker_structure_details(id),
                FOREIGN KEY (sticker_structure6_id) REFERENCES sticker_structure_details(id),
                FOREIGN KEY (sticker_structure7_id) REFERENCES sticker_structure_details(id),
                FOREIGN KEY (sticker_structure8_id) REFERENCES sticker_structure_details(id),

                FOREIGN KEY (sticker1_machine_id) REFERENCES machines(id),
                FOREIGN KEY (sticker2_machine_id) REFERENCES machines(id),
                FOREIGN KEY (sticker3_machine_id) REFERENCES machines(id),
                FOREIGN KEY (sticker4_machine_id) REFERENCES machines(id),
                FOREIGN KEY (sticker5_machine_id) REFERENCES machines(id),
                FOREIGN KEY (sticker6_machine_id) REFERENCES machines(id),
                FOREIGN KEY (sticker7_machine_id) REFERENCES machines(id),
                FOREIGN KEY (sticker8_machine_id) REFERENCES machines(id)
            );
        SQL;

        DB::statement($sql);
    }


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