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

                plant_id                            BIGINT NOT NULL,
                machine_id                          BIGINT NOT NULL,
                item_id                             BIGINT NOT NULL,
                characteristic_approver_master_id   BIGINT NOT NULL,
                aufnr                               TEXT DEFAULT NULL,
                characteristic_name                 TEXT DEFAULT NULL,
                current_value                       TEXT DEFAULT NULL,
                update_value                        TEXT DEFAULT NULL,

                approver_status1                    TEXT DEFAULT NULL,
                approver_status2                    TEXT DEFAULT NULL,
                approver_status3                    TEXT DEFAULT NULL,

                approver_remark1                    TEXT DEFAULT NULL,
                approver_remark2                    TEXT DEFAULT NULL,
                approver_remark3                    TEXT DEFAULT NULL,

                work_flow_id                        TEXT DEFAULT NULL,
                mail_status                         TEXT DEFAULT NULL,
                trigger_at                          TIMESTAMP,

                approved1_at			            TIMESTAMP,
                approved2_at			            TIMESTAMP,
                approved3_at			            TIMESTAMP,

                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 (machine_id) REFERENCES machines(id),
                FOREIGN KEY (item_id) REFERENCES items(id),
                FOREIGN KEY (characteristic_approver_master_id) REFERENCES characteristic_approver_masters(id)
            );
        SQL;
        DB::statement($sql);
    }

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