<?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::table('tenants', function (Blueprint $table) {
            $table->enum('tenant_type', ['STD', 'TPL', 'HQ'])
                ->default('STD')
                ->after('tenant_st_code')
                ->comment('테넌트 유형: STD=일반, TPL=템플릿, HQ=본사');
            $table->unsignedBigInteger('template_id')
                ->nullable()
                ->after('tenant_type')
                ->comment('복사된 템플릿 테넌트 ID');

            $table->foreign('template_id')
                ->references('id')
                ->on('tenants')
                ->nullOnDelete();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('tenants', function (Blueprint $table) {
            $table->dropForeign(['template_id']);
            $table->dropColumn(['tenant_type', 'template_id']);
        });
    }
};
