<?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
    {
        Schema::create('markets', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('base_currency', 10);
            $table->string('quote_currency', 10);
            $table->enum('status', ['active', 'inactive', 'maintenance'])->default('active');
            $table->decimal('maker_fee_rate', 5, 4)->default(0.0010); // 0.1%
            $table->decimal('taker_fee_rate', 5, 4)->default(0.0020); // 0.2%
            $table->decimal('min_order_size', 20, 8)->default(0.001);
            $table->tinyInteger('price_precision')->default(8);
            $table->tinyInteger('quantity_precision')->default(8);
            $table->boolean('enabled')->default(true);
            $table->timestamps();
            
            $table->index(['base_currency']);
            $table->index(['quote_currency']);
            $table->index(['status']);
            $table->index(['enabled']);
            $table->unique(['base_currency', 'quote_currency']); // Prevent duplicate markets
        });
    }

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