<?php

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

return new class extends Migration
{
    // 설계 버전: model_versions
    public function up(): void
    {
        Schema::create('model_versions', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('tenant_id')->comment('테넌트ID');
            $table->unsignedBigInteger('model_id')->comment('모델ID');
            $table->integer('version_no')->comment('버전번호(1..N)');
            $table->string('status', 30)->default('DRAFT')->comment('DRAFT/RELEASED');
            $table->dateTime('effective_from')->nullable();
            $table->dateTime('effective_to')->nullable();
            $table->text('notes')->nullable();
            $table->boolean('is_active')->default(true);
            $table->timestamps();
            $table->softDeletes();

            $table->unique(['model_id', 'version_no'], 'uq_model_versions_model_ver');
            $table->index(['tenant_id', 'status'], 'idx_mv_tenant_status');
            $table->index(['tenant_id', 'model_id'], 'idx_mv_tenant_model');
        });
    }

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