<?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_masters (
            id                    			BIGINT GENERATED always AS IDENTITY PRIMARY KEY,

            item_id				            BIGINT NOT NULL,
            plant_id				        BIGINT NOT NULL,

            serial_number_motor             TEXT DEFAULT NULL,
            serial_number_pump              TEXT DEFAULT NULL,
            serial_number_pumpset           TEXT DEFAULT NULL,

            pack_slip_motor       			TEXT DEFAULT NULL,
            pack_slip_pump        			TEXT DEFAULT NULL,
            pack_slip_pumpset     			TEXT DEFAULT NULL,

            name_plate_motor     		    TEXT DEFAULT NULL,
            name_plate_pump       			TEXT DEFAULT NULL,
            name_plate_pumpset    			TEXT DEFAULT NULL,

            tube_sticker_motor    			TEXT DEFAULT NULL,
            tube_sticker_pump    		    TEXT DEFAULT NULL,
            tube_sticker_pumpset  			TEXT DEFAULT NULL,

            warranty_card         			TEXT DEFAULT NULL,
            part_validation1      			TEXT DEFAULT NULL,
            part_validation2      			TEXT DEFAULT NULL,
            part_validation3      			TEXT DEFAULT NULL,
            part_validation4      			TEXT DEFAULT NULL,
            part_validation5      			TEXT DEFAULT NULL,

            panel_box_code                  TEXT DEFAULT NULL,
            load_rate                       INT NOT NULL DEFAULT (0),

            bundle_quantity                 INT DEFAULT NULL,
            material_type                   INT DEFAULT NULL,

            created_at      				TIMESTAMP NOT NULL DEFAULT NOW(),
            updated_at      				TIMESTAMP NOT NULL DEFAULT NOW(),
            deleted_at      				TIMESTAMP,

            UNIQUE (plant_id, item_id),
            FOREIGN KEY (item_id)  REFERENCES  items (id),
            FOREIGN KEY (plant_id) REFERENCES  plants (id)
        );
    SQL;

DB::statement($sql);
    }

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