<?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('sales_scenario_checklists', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->constrained()->cascadeOnDelete();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->unsignedTinyInteger('step_id')->comment('단계 ID (1-6)');
            $table->unsignedTinyInteger('checkpoint_index')->comment('체크포인트 인덱스');
            $table->boolean('is_checked')->default(true);
            $table->timestamps();

            // 복합 유니크 키: 사용자별, 단계별, 체크포인트별 하나의 레코드
            $table->unique(['tenant_id', 'user_id', 'step_id', 'checkpoint_index'], 'sales_scenario_unique');
            $table->index(['tenant_id', 'user_id']);
        });
    }

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