<?php

namespace Modules\AbaxisLab\Providers;

use Illuminate\Support\ServiceProvider;

class AbaxisLabServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $this->registerConfig();
        $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
        $this->registerLabCoreDriver();

        if ($this->app->runningInConsole()) {
            $this->commands([
                \Modules\AbaxisLab\Console\AbaxisSimulator::class,
            ]);
        }
    }

    public function register()
    {
        $this->app->register(RouteServiceProvider::class);
    }

    protected function registerConfig()
    {
        $this->publishes([
            __DIR__ . '/../Config/config.php' => config_path('abaxislab.php'),
        ], 'config');
        $this->mergeConfigFrom(
            __DIR__ . '/../Config/config.php', 'abaxislab'
        );
    }

    /**
     * Register the Abaxis driver with the LabCore engine. Degrades gracefully
     * if LabCore is somehow absent.
     */
    protected function registerLabCoreDriver(): void
    {
        if (class_exists(\Modules\LabCore\Entities\Services\DriverRegistry::class)) {
            \Modules\LabCore\Entities\Services\DriverRegistry::register(
                new \Modules\AbaxisLab\Entities\Drivers\AbaxisDriver()
            );
        }
    }

    public function provides()
    {
        return [];
    }
}
