<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('performance_reports', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->constrained();
            $table->foreignId('quality_document_id')->constrained();
            $table->unsignedSmallInteger('year')->comment('연도');
            $table->unsignedTinyInteger('quarter')->comment('분기 1-4');
            $table->string('confirmation_status', 20)->default('unconfirmed')->comment('unconfirmed/confirmed/reported');
            $table->date('confirmed_date')->nullable();
            $table->foreignId('confirmed_by')->nullable()->constrained('users');
            $table->text('memo')->nullable();
            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();
            $table->unsignedBigInteger('deleted_by')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->unique(['tenant_id', 'quality_document_id']);
            $table->index(['tenant_id', 'year', 'quarter']);
            $table->index(['tenant_id', 'confirmation_status']);
        });
    }

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