<?php

namespace App\Providers;

use App\Models\Document;
use App\Models\Guide;
use App\Observers\DocumentObserver;
use App\Policies\GuidePolicy;
use Carbon\Carbon;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        // 配置 Carbon 使用中文
        Carbon::setLocale('zh_CN');

        // 注册文档观察者，用于自动管理 Meilisearch 索引
        Document::observe(DocumentObserver::class);

        // 注册策略
        Gate::policy(\App\Models\Document::class, \App\Policies\DocumentPolicy::class);
        Gate::policy(\App\Models\Terminal::class, \App\Policies\TerminalPolicy::class);
        Gate::policy(Guide::class, GuidePolicy::class);
        Gate::policy(\Spatie\Permission\Models\Role::class, \App\Policies\RolePolicy::class);
        Gate::policy(\App\Models\User::class, \App\Policies\UserPolicy::class);
        Gate::policy(\App\Models\SystemSetting::class, \App\Policies\SystemSettingPolicy::class);
        Gate::policy(\Spatie\Activitylog\Models\Activity::class, \App\Policies\ActivityLogPolicy::class);
        Gate::policy(\App\Models\Station::class, \App\Policies\StationPolicy::class);
    }
}
