<?php

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

class CreatePaymentCallbackLogsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('payment_callback_logs', function (Blueprint $table) {
            $table->id();
            $table->string('payment_type', 50)->comment('支付类型');
            $table->string('out_trade_no', 100)->comment('商户订单号');
            $table->string('trade_no', 100)->nullable()->comment('支付平台订单号');
            $table->string('method', 10)->comment('请求方法');
            $table->string('uri', 255)->comment('请求URI');
            $table->json('headers')->comment('请求头');
            $table->json('query')->nullable()->comment('查询参数');
            $table->longText('body')->nullable()->comment('请求体');
            $table->string('ip', 50)->comment('客户端IP');
            $table->string('user_agent')->nullable()->comment('用户代理');
            $table->string('status', 20)->default('pending')->comment('处理状态');
            $table->json('response')->nullable()->comment('响应数据');
            $table->text('error_message')->nullable()->comment('错误信息');
            $table->integer('processing_time')->default(0)->comment('处理时间(毫秒)');
            $table->timestamps();
            $table->index('payment_type');
            $table->index('out_trade_no');
            $table->index('trade_no');
            $table->index('status');
            $table->index('created_at');
        });
    }

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