<?php

namespace Kylin\World;

use Illuminate\Support\ServiceProvider;
use Kylin\World\Services\RegionService;

/**
 * 世界行政区划服务提供者
 *
 * 提供全球/中国省市区三级行政区划数据查询服务。
 * 支持数据导入命令和区域查询 API。
 */
class WorldServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->mergeConfigFrom(__DIR__ . '/../config/kylin-world.php', 'kylin-world');
        $this->app->singleton(RegionService::class);
        $this->app->singleton('kylin-world', RegionService::class);
    }

    public function boot(): void
    {
        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');

        $this->publishes([
            __DIR__ . '/../config/kylin-world.php' => config_path('kylin-world.php'),
        ], 'kylin-world-config');

        $this->publishes([
            __DIR__ . '/../database/seeders' => database_path('seeders'),
        ], 'kylin-world-seeders');

        if ($this->app->runningInConsole()) {
            $this->commands([
                Commands\ImportRegionsCommand::class,
            ]);
        }
    }
}
