<?php

use App\Http\Controllers\ProfileController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\WalletController;
use App\Http\Controllers\PhonebookController;
use App\Http\Controllers\ContactController;
use App\Http\Controllers\VoiceRecordController;
use App\Http\Controllers\CampaignController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return redirect()->route('login');
});

// SSLCommerz callback routes - MUST be outside auth middleware
Route::post('/wallet/success', [WalletController::class, 'success'])->name('wallet.success');
Route::post('/wallet/fail', [WalletController::class, 'fail'])->name('wallet.fail');
Route::post('/wallet/cancel', [WalletController::class, 'cancel'])->name('wallet.cancel');

Route::middleware(['auth', 'verified'])->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

    // Wallet (only index and pay need auth)
    Route::get('/wallet', [WalletController::class, 'index'])->name('wallet.index');
    Route::post('/wallet/pay', [WalletController::class, 'pay'])->name('wallet.pay');

    // Phonebook & Contacts
    Route::resource('phonebooks', PhonebookController::class);
    Route::resource('contacts', ContactController::class);
    Route::post('contacts/import', [ContactController::class, 'import'])->name('contacts.import');

    // Voice Records
    Route::resource('voice-records', VoiceRecordController::class);

    // Campaigns
    Route::resource('campaigns', CampaignController::class);
});

Route::middleware('auth')->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
});

require __DIR__.'/auth.php';
