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

                plant_id                    BIGINT NOT NULL,
                item_id                     BIGINT NOT NULL,

                isi_model					BOOLEAN DEFAULT FALSE,
                phase               		TEXT NOT NULL,
                hp			                TEXT NOT NULL,
                kw                  		TEXT NOT NULL,

                volt              			TEXT NOT NULL,
                current               		TEXT NOT NULL,
                rpm               			TEXT NOT NULL,
                torque                  	TEXT NOT NULL,
                frequency                  	TEXT NOT NULL,
                connection                  TEXT NOT NULL,
                ins_res_limit               TEXT NOT NULL,
                ins_res_type               	TEXT NOT NULL DEFAULT 'O',

                res_ry_ll              		TEXT NOT NULL DEFAULT '0.05',
                res_ry_ul              		TEXT NOT NULL DEFAULT '99',
                res_yb_ll              		TEXT NOT NULL DEFAULT '0.05',
                res_yb_ul              		TEXT NOT NULL DEFAULT '99',
                res_br_ll              		TEXT NOT NULL DEFAULT '0.05',
                res_br_ul              		TEXT NOT NULL DEFAULT '99',

                lock_volt_limit				TEXT NOT NULL,
                leak_cur_limit				TEXT NOT NULL,
                lock_cur_ll					TEXT NOT NULL,
                lock_cur_ul					TEXT NOT NULL,

                noload_cur_ll				TEXT NOT NULL,
                noload_cur_ul				TEXT NOT NULL,

                noload_pow_ll				TEXT NOT NULL,
                noload_pow_ul				TEXT NOT NULL,

                noload_spd_ll				TEXT NOT NULL,
                noload_spd_ul				TEXT NOT NULL,

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

                created_by					TEXT NOT NULL,
                updated_by					TEXT NOT NULL,

                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('motor_testing_masters');
    }
};
