<?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
    {
        if (Schema::hasTable('pd_order_status_histories')) {
            return;
        }

        Schema::create('pd_order_status_histories', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('pd_order_id')->index();
            $table->unsignedBigInteger('user_id')->nullable()->index();
            $table->unsignedBigInteger('admin_id')->nullable()->index();
            $table->string('admin_name', 191)->nullable();
            $table->string('action', 80)->index();
            $table->string('from_status', 40)->nullable()->index();
            $table->string('to_status', 40)->nullable()->index();
            $table->text('description')->nullable();
            $table->text('user_message')->nullable();
            $table->json('metadata')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        if (Schema::hasTable('pd_order_status_histories')) {
            Schema::drop('pd_order_status_histories');
        }
    }
};

