<?php

declare(strict_types=1);

namespace Maestro\Core\Modules\Items\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Maestro\Core\Modules\Items\Models\Item;
use Maestro\Core\Support\CorePaths;

class ItemsModuleServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        if (config('core.modules.items', true) !== true) {
            return;
        }

        Route::bind('item', fn (string $value): Item => Item::query()->whereKey($value)->firstOrFail());

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

        $this->loadRoutesFrom(CorePaths::packageRoot().'/routes/modules/items.php');
    }
}
