<?php

namespace App\Modules\ThreeCX;

use App\Modules\ThreeCX\Services\ThreeCXAuthService;
use App\Modules\ThreeCX\Services\ThreeCXMakeCallService;
use App\Modules\ThreeCX\Services\ThreeCXCallTrackingService;

class ThreeCXServiceProvider extends \App\Modules\ServiceProvider
{
    public function register()
    {
        // Pass the canonical folder name so the lookup works
        parent::register('threecx');

        // Register services
        $this->app->singleton(ThreeCXAuthService::class);
        $this->app->singleton(ThreeCXMakeCallService::class);
        $this->app->singleton(ThreeCXCallTrackingService::class);
    }

    public function boot()
    {
        parent::boot('ThreeCX');

        // Load views for WebSocket setup templates
        $this->loadViewsFrom(__DIR__ . '/views', 'threecx');

        // Load configuration
        $this->mergeConfigFrom(
            __DIR__ . '/../../../config/threecx.php',
            'threecx'
        );

        if ($this->app->runningInConsole()) {
            $this->publishes([
                __DIR__ . '/../../../config/threecx.php' => config_path('threecx.php'),
            ], 'threecx-config');
        }
    }
}
