<?php

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

return new class extends Migration
{
    /**
     * バッチログテーブルの作成
     * 
     * SHJ-4C室割当処理を含む全てのバッチ処理のログを記録
     */
    public function up(): void
    {
        Schema::create('batch_log', function (Blueprint $table) {
            $table->id();
            $table->string('process_name', 50)->comment('プロセス名');
            $table->string('status', 20)->comment('ステータス');
            $table->datetime('start_time')->comment('開始時刻');
            $table->datetime('end_time')->nullable()->comment('終了時刻');
            $table->json('parameters')->nullable()->comment('パラメータ（JSON形式）');
            $table->text('message')->nullable()->comment('メッセージ');
            $table->text('error_details')->nullable()->comment('エラー詳細');
            $table->integer('execution_count')->default(0)->comment('実行回数');
            $table->integer('success_count')->default(0)->comment('成功回数');
            $table->integer('error_count')->default(0)->comment('エラー回数');
            $table->timestamps();
            
            // インデックス作成
            $table->index(['process_name', 'status']);
            $table->index('start_time');
            $table->index('status');
        });
    }

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