<?php

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

return new class extends Migration {
    public function up(): void
    {
        Schema::table('operational_documents', function (Blueprint $table) {
            $table->foreignId('parent_id')->nullable()->index();
            $table->foreignId('trade_document_id')->nullable()->index();
            $table->dateTime('approved_at')->nullable();
            $table->foreignId('approved_by')->nullable()->index();
        });
        Schema::create('operational_document_histories', function (Blueprint $table) {
            $table->id(); $table->foreignId('operational_document_id')->index();
            $table->foreignId('user_id')->nullable()->index();
            $table->string('action'); $table->string('from_status')->nullable(); $table->string('to_status');
            $table->text('comment')->nullable(); $table->timestamps();
        });
    }
    public function down(): void
    {
        Schema::dropIfExists('operational_document_histories');
        Schema::table('operational_documents', fn(Blueprint $table) => $table->dropColumn(['parent_id','trade_document_id','approved_at','approved_by']));
    }
};
