<?php

namespace Kylin\AntiAddiction;

use Illuminate\Support\ServiceProvider;
use Kylin\AntiAddiction\Services\AntiAddictionService;
use Kylin\AntiAddiction\Services\BehaviorAnalysisService;
use Kylin\AntiAddiction\Services\FaceVerifyService;
use Kylin\AntiAddiction\Services\HolidayService;
use Kylin\AntiAddiction\Services\RealNameVerifyService;

/**
 * 防沉迷系统服务提供者
 *
 * 提供游戏防沉迷管控服务，包括：
 *  - 实名认证（RealNameVerifyService）
 *  - 人脸验证（FaceVerifyService）
 *  - 行为分析（BehaviorAnalysisService）
 *  - 节假日时长管理（HolidayService）
 */
class AntiAddictionServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->mergeConfigFrom(
            __DIR__ . '/../config/kylin-anti-addiction.php', 'kylin-anti-addiction'
        );

        // 注册服务为单例
        $this->app->singleton(HolidayService::class);
        $this->app->singleton(AntiAddictionService::class);
        $this->app->singleton(RealNameVerifyService::class);
        $this->app->singleton(FaceVerifyService::class);
        $this->app->singleton(BehaviorAnalysisService::class);

        // 注册门面对应的别名
        $this->app->singleton('kylin-anti-addiction', AntiAddictionService::class);
    }

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

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

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

        $this->loadRoutesFrom(__DIR__ . '/../routes/api.php');
    }
}
