<?php

/*
|--------------------------------------------------------------------------
| Module Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for this module.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

// 3CX Integration - Search route for phone number lookup (public access)
Route::get('search', 'App\Http\Controllers\SearchController@searchByNumber');

Route::group(['prefix' => Config::get('app.api_path'), 'middleware' => ['web', 'auth', 'adminCheck']], function () {
    // Integrations API routes
    Route::get('integrations/status', 'App\Modules\Admin\IntegrationsController@status');
    Route::post('integrations/test-sms', 'App\Modules\Admin\IntegrationsController@testSMS');
    Route::post('integrations/test-phone-system', 'App\Modules\Admin\IntegrationsController@testPhoneSystem');
    Route::post('integrations/test-3cx', 'App\Modules\Admin\IntegrationsController@test3CX');
    Route::post('integrations/test-3cx-call', 'App\Modules\Admin\IntegrationsController@test3CXCall');
    Route::get('integrations/threecx-extensions', 'App\Modules\Admin\IntegrationsController@getThreeCXExtensions');
    Route::post('integrations/test-xero', 'App\Modules\Admin\IntegrationsController@testXero');
    Route::post('integrations/test-textmagic', 'App\Modules\Admin\IntegrationsController@testTextMagic');
    Route::post('integrations/test-office365', 'App\Modules\Admin\IntegrationsController@testOffice365');
    Route::get('integrations/office365-calendars', 'App\Modules\Admin\IntegrationsController@getOffice365Calendars');

    // TextMagic SMS routes
    Route::post('textmagic/send', 'App\Modules\TextMagic\Controllers\TextMagicApiController@send');
    Route::post('textmagic/test-credentials', 'App\Modules\TextMagic\Controllers\TextMagicApiController@testCredentials');
    // KashFlow test route removed - migrated to Xero
});

/*
|--------------------------------------------------------------------------
| Pages rendered on the server
|--------------------------------------------------------------------------
|
| This group routes are pages rendered on the server.
| All the pages require the user to be authentificated.
|
*/

Route::group(['middleware' => ['web', 'auth', 'adminCheck'], 'prefix' => 'admin/settings', 'as' => 'admin.settings.'], function () {
    Route::get('users', ['uses' => 'App\Modules\Admin\UsersController@index']);
    Route::resource('groups', 'App\Modules\Admin\GroupsController');
    Route::resource('statuses', 'App\Modules\Admin\StatusController');
    Route::resource('contracts', 'App\Modules\Admin\ContractsController');
    Route::post('emails/enable', ['as' => 'emails.enable', 'uses' => 'App\Modules\Admin\EmailsController@enable']);
    Route::post('emails/disable', ['as' => 'emails.disable', 'uses' => 'App\Modules\Admin\EmailsController@disable']);
    Route::post('emails/test-imap', ['as' => 'emails.test-imap', 'uses' => 'App\Modules\Admin\EmailsController@testImapConnection']);
    Route::post('emails/test-smtp', ['as' => 'emails.test-smtp', 'uses' => 'App\Modules\Admin\EmailsController@testSmtpConnection']);
    Route::resource('emails', 'App\Modules\Admin\EmailsController');
    Route::resource('rest', 'App\Modules\Admin\RestController');
    Route::get('task-templates', ['as' => 'task-templates', 'uses' => 'App\Modules\Admin\TaskTemplatesController@index']);
    Route::get('events', ['as' => 'events', 'uses' => 'App\Modules\Admin\EventsController@index']);
    Route::post('ldap/test-settings', ['as' => 'ldap.test', 'uses' => 'App\Modules\Admin\AdldapController@testSettings']);
    Route::resource('ldap', 'App\Modules\Admin\AdldapController');
    Route::get('integrations', ['as' => 'integrations.index', 'uses' => 'App\Modules\Admin\IntegrationsController@index']);
    Route::post('integrations', ['as' => 'integrations.update', 'uses' => 'App\Modules\Admin\IntegrationsController@update']);
    Route::get('office365/callback', ['as' => 'office365.callback', 'uses' => 'App\Modules\Admin\IntegrationsController@office365Callback']);
    Route::get('api-keys', ['as' => 'api-keys.index', 'uses' => 'App\Modules\Admin\ApiKeysController@index']);
    Route::post('api-keys/generate', ['as' => 'api-keys.generate', 'uses' => 'App\Modules\Admin\ApiKeysController@generate']);
    Route::post('api-keys/regenerate', ['as' => 'api-keys.regenerate', 'uses' => 'App\Modules\Admin\ApiKeysController@regenerate']);
    Route::get('api-keys/download-xml', ['as' => 'api-keys.download-xml', 'uses' => 'App\Modules\Admin\ApiKeysController@downloadXml']);
});

// Dashboard Tabs Settings Routes
Route::group(['middleware' => ['web', 'auth', 'adminCheck'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
    Route::post('dashboard-tabs/reset', ['as' => 'dashboard-tabs.reset', 'uses' => 'App\Modules\Admin\controllers\DashboardTabsController@resetToDefault']);
    Route::put('dashboard-tabs/update-all', ['as' => 'dashboard-tabs.update-all', 'uses' => 'App\Modules\Admin\controllers\DashboardTabsController@updateAll']);
    Route::get('dashboard-tabs', ['as' => 'dashboard-tabs.index', 'uses' => 'App\Modules\Admin\controllers\DashboardTabsController@index']);
});

// Additional admin routes (without settings prefix)
Route::group(['middleware' => ['web', 'auth', 'adminCheck'], 'prefix' => 'admin'], function () {
    Route::post('integrations/threecx/test-call', 'App\Modules\Admin\IntegrationsController@testCall');
    Route::get('integrations/threecx/call-status/{participantId}', 'App\Modules\Admin\IntegrationsController@getCallStatus');
    Route::post('integrations/threecx/hangup-call', 'App\Modules\Admin\IntegrationsController@hangupCall');
});
Route::get('task-templates', ['uses' => 'App\Modules\Admin\TaskTemplatesController@index']);
Route::group(['middleware' => ['web', 'auth', 'adminCheck']], function () {
    Route::get('admin', 'App\Modules\Admin\AdminController@getIndex');
});
