<?php

declare(strict_types=1);

namespace Kylin\Holiday;

use Illuminate\Support\ServiceProvider;
use Kylin\Holiday\Commands\UpdateHolidayCommand;
use Kylin\Holiday\Services\HolidayService;

/**
 * 节假日查询服务提供者
 *
 * 提供中国法定节假日、调休工作日查询服务。
 * 支持年份区间查询和日期范围判断。
 */
class HolidayServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->mergeConfigFrom(__DIR__ . '/../config/kylin-holiday.php', 'kylin-holiday');
        $this->app->singleton(HolidayService::class);
        $this->app->singleton('kylin-holiday', HolidayService::class);
    }

    public function boot(): void
    {
        if ($this->app->runningInConsole()) {
            $this->publishes([
                __DIR__ . '/../config/kylin-holiday.php' => config_path('kylin-holiday.php'),
            ], 'kylin-holiday-config');

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

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

            $this->commands([UpdateHolidayCommand::class]);
        }

        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
    }
}
