<?php

namespace App\Services\TenantBootstrap\Steps;

use App\Services\TenantBootstrap\Contracts\TenantBootstrapStep;
use Illuminate\Support\Facades\DB;

class CategoriesStep implements TenantBootstrapStep
{
    public function key(): string
    {
        return 'categories_seed';
    }

    public function run(int $tenantId): void
    {
        $exists = DB::table('categories')->where([
            'tenant_id' => $tenantId, 'code_group' => 'product', 'code' => 'DEFAULT',
        ])->exists();

        if (! $exists) {
            DB::table('categories')->insert([
                'tenant_id' => $tenantId,
                'parent_id' => null,
                'code_group' => 'product',
                'code' => 'DEFAULT',
                'name' => '기본 카테고리',
                'profile_code' => 'FINISHED_GOOD',
                'is_active' => 1,
                'sort_order' => 1,
                'created_at' => now(),
                'updated_at' => now(),
            ]);
        }
    }
}
