<?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('quality_document_locations', function (Blueprint $table) {
            $table->id();
            $table->foreignId('quality_document_id')->constrained()->cascadeOnDelete();
            $table->foreignId('quality_document_order_id')->constrained('quality_document_orders', 'id', 'qdl_qdo_id_fk')->cascadeOnDelete();
            $table->foreignId('order_item_id')->constrained('order_items');
            $table->integer('post_width')->nullable()->comment('시공후 가로');
            $table->integer('post_height')->nullable()->comment('시공후 세로');
            $table->string('change_reason')->nullable()->comment('규격 변경사유');
            $table->foreignId('document_id')->nullable()->comment('검사성적서 문서 ID');
            $table->string('inspection_status', 20)->default('pending')->comment('pending/completed');
            $table->timestamps();

            $table->index(['quality_document_id', 'inspection_status'], 'qdl_doc_id_status_index');
        });
    }

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