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

                item_id                     BIGINT NOT NULL,
                plant_id                    BIGINT NOT NULL,

                obd_number                  TEXT NOT NULL,
                line_number                 TEXT DEFAULT NULL,
                batch_number                TEXT DEFAULT NULL,
                heat_number                 TEXT DEFAULT NULL,
                obd_weight                  TEXT DEFAULT NULL,

                vehicle_number              TEXT DEFAULT NULL,
                bundle_number               TEXT DEFAULT NULL,
                picked_weight               TEXT DEFAULT NULL,
                scanned_by                  TEXT DEFAULT NULL,

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

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