<?php

use Illuminate\Support\Facades\Route;
use App\Modules\Twilio\Controllers\TwilioApiController;
use App\Modules\Twilio\Controllers\TwilioAuthController;

/*
|--------------------------------------------------------------------------
| Twilio Module Routes
|--------------------------------------------------------------------------
|
| Here are the routes for the Twilio module. These routes are loaded
| by the TwilioServiceProvider when the module is booted.
|
*/

// API Routes
Route::prefix('api/v1/twilio')->group(function () {
    
    // API Controller Routes
    Route::controller(TwilioApiController::class)->group(function () {
        // SMS Operations
        Route::post('/send', 'sendSMS');
        Route::get('/status/{messageSid}', 'getDeliveryStatus');
        Route::get('/history', 'getSMSHistory');
        Route::post('/validate-phone', 'validatePhoneNumber');
        Route::post('/format-phone', 'formatPhoneNumber');
        Route::get('/connection/test', 'testConnection');
        Route::get('/account/numbers', 'getAvailableNumbers');
    });
    
    // Auth Controller Routes
    Route::controller(TwilioAuthController::class)->group(function () {
        Route::get('/config/status', 'getConfigurationStatus');
        Route::post('/config/update', 'updateConfiguration');
        Route::post('/config/test-credentials', 'testCredentials');
        Route::get('/config/account-info', 'getAccountInfo');
        Route::get('/config/account-numbers', 'getAccountNumbers');
        Route::post('/config/validate-number', 'validateNumber');
        Route::get('/config/usage-stats', 'getUsageStats');
        Route::post('/config/reset', 'resetConfiguration');
    });
});

// Task-specific SMS routes (compatible with existing API)
Route::prefix('api/v1/tasks')->group(function () {
    Route::controller(TwilioApiController::class)->group(function () {
        Route::post('/{taskId}/sms', 'sendTaskSMS');
        Route::post('/{taskId}/completion-sms', 'sendCompletionSMS');
    });
});

// Legacy SMS route (for backward compatibility)
Route::post('api/v1/sms/send', [TwilioApiController::class, 'sendSMS']); 