<?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('ai_reports', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->constrained()->comment('테넌트 ID');
            $table->date('report_date')->comment('리포트 기준일');
            $table->string('report_type', 50)->default('daily')->comment('리포트 유형: daily/weekly/monthly');
            $table->json('content')->nullable()->comment('리포트 내용 (영역별 분석 배열)');
            $table->text('summary')->nullable()->comment('요약 메시지');
            $table->json('input_data')->nullable()->comment('AI 분석에 사용된 입력 데이터');
            $table->string('status', 20)->default('completed')->comment('상태: pending/completed/failed');
            $table->text('error_message')->nullable()->comment('실패 시 에러 메시지');
            $table->foreignId('created_by')->nullable()->constrained('users')->comment('생성자 ID');
            $table->timestamps();

            $table->index(['tenant_id', 'report_date'], 'idx_tenant_date');
            $table->index(['tenant_id', 'report_type'], 'idx_tenant_type');
        });
    }

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