<?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
    {
        // products 테이블에 is_active 추가 (컬럼이 없을 때만)
        Schema::table('products', function (Blueprint $table) {
            if (! Schema::hasColumn('products', 'is_active')) {
                $table->tinyInteger('is_active')
                    ->default(1)
                    ->after('updated_by')
                    ->comment('활성 상태 (1: 활성, 0: 비활성)');
            }
        });

        // materials 테이블에 is_active 추가 (컬럼이 없을 때만)
        Schema::table('materials', function (Blueprint $table) {
            if (! Schema::hasColumn('materials', 'is_active')) {
                $table->tinyInteger('is_active')
                    ->default(1)
                    ->after('updated_by')
                    ->comment('활성 상태 (1: 활성, 0: 비활성)');
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // products 테이블에서 is_active 제거
        Schema::table('products', function (Blueprint $table) {
            $table->dropColumn('is_active');
        });

        // materials 테이블에서 is_active 제거
        Schema::table('materials', function (Blueprint $table) {
            $table->dropColumn('is_active');
        });
    }
};
