<?php

declare(strict_types=1);

namespace Maestro\Core\Providers;

use Illuminate\Support\ServiceProvider;
use Maestro\Core\Console\Commands\CoreInstallCommand;
use Maestro\Core\Services\AutoSyncPackageStubs;

class CoreServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->mergeConfigFrom(__DIR__.'/../../config/core.php', 'core');
    }

    public function boot(): void
    {
        $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
        $this->loadRoutesFrom(__DIR__.'/../../routes/core.php');
        $this->loadViewsFrom(__DIR__.'/../../resources/views', 'maestro-core');

        if ($this->app->runningInConsole()) {
            (new AutoSyncPackageStubs)->syncIfStubsAreNewer();
            $this->commands([CoreInstallCommand::class]);
        }

        $this->publishes([
            __DIR__.'/../../config/core.php' => config_path('core.php'),
        ], 'core-config');
    }
}
