<?php

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

/**
 * PRC-1143 — konsolide şema: `order_fraud_checks` tablosunun TAM tanımı (tek dosya).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('order_fraud_checks', function (Blueprint $t) {
            $t->id();
            $t->unsignedBigInteger('order_id');
            $t->string('check_type', 255);
            $t->string('check_status', 255);
            $t->integer('risk_score')->default(0);
            $t->text('reason')->nullable();
            $t->json('check_data')->nullable();
            $t->json('metadata')->nullable();
            $t->integer('execution_time_ms')->nullable();
            $t->timestamp('checked_at');
            $t->timestamp('created_at')->nullable();
            $t->timestamp('updated_at')->nullable();
            $t->index('checked_at', 'order_fraud_checks_checked_at_index');
            $t->index('check_status', 'order_fraud_checks_check_status_index');
            $t->index(['order_id', 'check_type'], 'order_fraud_checks_order_id_check_type_index');
            $t->index('order_id', 'order_fraud_checks_order_id_index');
            $t->index('risk_score', 'order_fraud_checks_risk_score_index');
            $t->foreign('order_id', 'order_fraud_checks_order_id_foreign')->references('id')->on('orders')->onDelete('cascade');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('order_fraud_checks');
    }
};
