<?php

namespace Kylin\AuditLog;

use Illuminate\Support\ServiceProvider;
use Kylin\AuditLog\Commands\CleanAuditLogCommand;
use Kylin\AuditLog\Services\AuditLogService;

/**
 * 审计日志服务提供者
 *
 * 提供模型变更审计日志功能，自动记录 create/update/delete 操作。
 * 通过 Auditable Trait 为模型添加审计能力。
 */
class AuditLogServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->mergeConfigFrom(__DIR__ . '/../config/kylin-audit-log.php', 'kylin-audit-log');
        $this->app->singleton(AuditLogService::class);
        $this->app->singleton('kylin-audit-log', AuditLogService::class);
    }

    public function boot(): void
    {
        $this->publishes([__DIR__ . '/../config/kylin-audit-log.php' => config_path('kylin-audit-log.php')], 'kylin-audit-log-config');
        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
        $this->loadRoutesFrom(__DIR__ . '/../routes/api.php');

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