<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $sql = <<<'SQL'
            CREATE TABLE pump_testing_masters (
                id                     BIGINT GENERATED always AS IDENTITY PRIMARY KEY,

                plant_id               BIGINT NOT NULL,
                item_id                BIGINT NOT NULL,

                head                   TEXT DEFAULT NULL,
                head_type              TEXT DEFAULT NULL,
                discharge              TEXT DEFAULT NULL,
                discharge_type         TEXT DEFAULT NULL,
                motor_efficiency       TEXT DEFAULT NULL,
                pump_efficiency        TEXT DEFAULT NULL,
                speed                  TEXT DEFAULT NULL,
                frequency              TEXT DEFAULT NULL,
                i_max                  TEXT DEFAULT NULL,
                p_input                TEXT DEFAULT NULL,
                delivery_size          TEXT DEFAULT NULL,
                no_of_stages           TEXT DEFAULT NULL,
                size                   TEXT DEFAULT NULL,
                maximum_head           TEXT DEFAULT NULL,
                motor_type             TEXT DEFAULT NULL,
                motor_code             TEXT DEFAULT NULL,
                kw_hp                  TEXT DEFAULT NULL,
                connection_type        TEXT DEFAULT NULL,
                voltage                TEXT DEFAULT NULL,
                phase                  TEXT DEFAULT NULL,
                oh_minimum             TEXT DEFAULT NULL,
                oh_maximum             TEXT DEFAULT NULL,
                current_minimum        TEXT DEFAULT NULL,
                current_maximum        TEXT DEFAULT NULL,
                class_of_insulation    TEXT DEFAULT NULL,
                testing_code           TEXT DEFAULT 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('pump_testing_masters');
    }
};
