<?php

declare(strict_types=1);

namespace Kylin\Agriculture;

use Illuminate\Support\ServiceProvider;
use Kylin\Agriculture\Commands\CleanPesticideRecordsCommand;

/**
 * 智慧农业服务提供者
 *
 * 提供农业物联网管理功能：传感器监控、预警规则、农事记录、物料管理等。
 */
class AgricultureServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->mergeConfigFrom(
            __DIR__ . '/../config/kylin-agriculture.php',
            'kylin-agriculture'
        );
    }

    public function boot(): void
    {
        // 发布配置
        $this->publishes([
            __DIR__ . '/../config/kylin-agriculture.php' => config_path('kylin-agriculture.php'),
        ], 'kylin-agriculture-config');

        // 发布迁移
        $this->publishes([
            __DIR__ . '/../database/migrations/' => database_path('migrations'),
        ], 'kylin-agriculture-migrations');

        // 加载路由
        $this->loadRoutesFrom(__DIR__ . '/../routes/api.php');

        // 注册 Artisan 命令
        if ($this->app->runningInConsole()) {
            $this->commands([
                CleanPesticideRecordsCommand::class,
            ]);
        }
    }
}
