<?php

namespace Maestro\Core\Providers;

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

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()) {
            $this->commands([CoreInstallCommand::class]);
        }

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

        $this->publishes([
            __DIR__.'/../../stubs/routes/web.php' => base_path('routes/web.php'),
            __DIR__.'/../../stubs/vite.config.js' => base_path('vite.config.js'),
            __DIR__.'/../../stubs/tailwind.config.js' => base_path('tailwind.config.js'),
            __DIR__.'/../../stubs/resources/js/app.js' => resource_path('js/app.js'),
            __DIR__.'/../../stubs/resources/js/pages/Dashboard.vue' => resource_path('js/pages/Dashboard.vue'),
            __DIR__.'/../../stubs/.npmrc' => base_path('.npmrc'),
        ], 'core-stubs');
    }
}
