<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Admin Routes
|--------------------------------------------------------------------------
|
| Here is where you can register admin routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "admin" middleware group. Now create something great!
|
*/

Route::middleware(['auth', 'admin'])->group(function() {
    Route::get('/home', [App\Http\Controllers\Admin\HomeController::class, 'index'])->name('admin.home');
    Route::get('/analytics', [App\Http\Controllers\Admin\AnalyticsController::class, 'index'])->name('admin.analytics');
    Route::get('/analytics/export/offerwalls', [App\Http\Controllers\Admin\AnalyticsController::class, 'exportOfferwalls'])->name('admin.analytics.export.offerwalls');
    Route::get('/analytics/export/offers', [App\Http\Controllers\Admin\AnalyticsController::class, 'exportOffers'])->name('admin.analytics.export.offers');
    Route::post('/ai/chat', [App\Http\Controllers\Admin\AiAssistantController::class, 'chat'])->name('admin.ai.chat')->middleware('throttle:20,1');
    Route::get('/notifications/feed', [App\Http\Controllers\NotificationsController::class, 'adminFeed'])->name('admin.notifications.feed');

    // Centralized CSV exports for the admin bulk lists.
    Route::get('/export/all', [App\Http\Controllers\Admin\ExportController::class, 'all'])->name('admin.export.all');
    Route::get('/export/users', [App\Http\Controllers\Admin\ExportController::class, 'users'])->name('admin.export.users');
    Route::get('/export/withdrawals', [App\Http\Controllers\Admin\ExportController::class, 'withdrawals'])->name('admin.export.withdrawals');
    Route::get('/export/activity', [App\Http\Controllers\Admin\ExportController::class, 'activity'])->name('admin.export.activity');
    Route::get('/export/logs', [App\Http\Controllers\Admin\ExportController::class, 'logs'])->name('admin.export.logs');
    Route::get('/export/campaigns', [App\Http\Controllers\Admin\ExportController::class, 'campaigns'])->name('admin.export.campaigns');
    Route::get('/export/provider-offers', [App\Http\Controllers\Admin\ExportController::class, 'providerOffers'])->name('admin.export.provider-offers');
    Route::get('/export/tickets', [App\Http\Controllers\Admin\ExportController::class, 'tickets'])->name('admin.export.tickets');
    Route::get('/export/face-verifications', [App\Http\Controllers\Admin\ExportController::class, 'faceVerifications'])->name('admin.export.face-verifications');
    Route::get('/activity', [App\Http\Controllers\Admin\ActivityController::class, 'index'])->name('admin.activity');
    Route::post('/activity/bulk', [App\Http\Controllers\Admin\ActivityController::class, 'bulk'])->name('admin.activity.bulk');
    Route::get('/referrals', [App\Http\Controllers\Admin\ReferralsController::class, 'index'])->name('admin.referrals');
    Route::get('/logs', [App\Http\Controllers\Admin\CallbackLogsController::class, 'index'])->name('admin.logs');
    Route::post('/logs/bulk', [App\Http\Controllers\Admin\CallbackLogsController::class, 'bulk'])->name('admin.logs.bulk');
    Route::get('/tickets', [App\Http\Controllers\Admin\SupportTicketsController::class, 'index'])->name('admin.tickets');
    Route::post('/tickets/bulk', [App\Http\Controllers\Admin\SupportTicketsController::class, 'bulk'])->name('admin.tickets.bulk');
    Route::get('/tickets/{ticket}', [App\Http\Controllers\Admin\SupportTicketsController::class, 'show'])->name('admin.tickets.show');
    Route::post('/tickets/{ticket}', [App\Http\Controllers\Admin\SupportTicketsController::class, 'reply'])->name('admin.tickets.reply');
    Route::get('/users', [App\Http\Controllers\Admin\UsersController::class, 'index'])->name('admin.users');
    Route::view('/withdrawals', 'admin.withdrawals')->name('admin.withdrawals');
    Route::view('/offerwalls', 'admin.offerwalls')->name('admin.offerwalls');
    Route::get('/provider-offers', [App\Http\Controllers\Admin\ProviderOffersController::class, 'index'])->name('admin.provider-offers');
    Route::post('/provider-offers/sync', [App\Http\Controllers\Admin\ProviderOffersController::class, 'syncAll'])->name('admin.provider-offers.sync');
    Route::post('/provider-offers/sync/{offerwall}', [App\Http\Controllers\Admin\ProviderOffersController::class, 'syncProvider'])->name('admin.provider-offers.sync-provider');
    Route::patch('/provider-offers/{providerOffer}', [App\Http\Controllers\Admin\ProviderOffersController::class, 'update'])->name('admin.provider-offers.update');
    Route::post('/provider-offers/curate', [App\Http\Controllers\Admin\ProviderOffersController::class, 'curateNow'])->name('admin.provider-offers.curate');
    Route::post('/provider-offers/bulk', [App\Http\Controllers\Admin\ProviderOffersController::class, 'bulk'])->name('admin.provider-offers.bulk');
    Route::get('/campaigns', [App\Http\Controllers\Admin\CampaignsController::class, 'index'])->name('admin.campaigns');
    Route::post('/campaigns', [App\Http\Controllers\Admin\CampaignsController::class, 'store'])->name('admin.campaigns.store');
    Route::post('/campaigns/bulk', [App\Http\Controllers\Admin\CampaignsController::class, 'bulk'])->name('admin.campaigns.bulk');
    Route::patch('/campaigns/{campaign}', [App\Http\Controllers\Admin\CampaignsController::class, 'update'])->name('admin.campaigns.update');
    Route::delete('/campaigns/{campaign}', [App\Http\Controllers\Admin\CampaignsController::class, 'destroy'])->name('admin.campaigns.destroy');
    Route::get('/payments', [App\Http\Controllers\Admin\PaymentsController::class, 'index'])->name('admin.payments');
    Route::get('/payments/{id}', [App\Http\Controllers\Admin\PaymentsController::class, 'view'])->name('admin.payments.view');
    Route::post('/payments/{id}', [App\Http\Controllers\Admin\PaymentsController::class, 'update'])->name('admin.payments.update');
    Route::get('/payments/{id}/{price_id}', [App\Http\Controllers\Admin\PaymentsController::class, 'view'])->name('admin.payments.view.price');
    Route::get('/face-verifications', [App\Http\Controllers\Admin\FaceVerificationsController::class, 'index'])->name('admin.face-verifications');
    Route::post('/face-verifications/bulk', [App\Http\Controllers\Admin\FaceVerificationsController::class, 'bulk'])->name('admin.face-verifications.bulk');
    Route::get('/leads', [App\Http\Controllers\Admin\LeadsController::class, 'index'])->name('admin.leads');
    Route::get('/leads/export', [App\Http\Controllers\Admin\LeadsController::class, 'export'])->name('admin.leads.export');
    Route::post('/leads/rules', [App\Http\Controllers\Admin\LeadsController::class, 'storeRule'])->name('admin.leads.rules.store');
    Route::delete('/leads/rules/{rule}', [App\Http\Controllers\Admin\LeadsController::class, 'destroyRule'])->name('admin.leads.rules.destroy');
    Route::post('/leads/rules/{rule}/toggle', [App\Http\Controllers\Admin\LeadsController::class, 'toggleRule'])->name('admin.leads.rules.toggle');
    Route::post('/leads/default-status', [App\Http\Controllers\Admin\LeadsController::class, 'saveDefaultStatus'])->name('admin.leads.default-status');
    Route::patch('/leads/{lead}', [App\Http\Controllers\Admin\LeadsController::class, 'update'])->name('admin.leads.update');
    Route::post('/leads/bulk', [App\Http\Controllers\Admin\LeadsController::class, 'bulk'])->name('admin.leads.bulk');
    Route::get('/leaderboard', [App\Http\Controllers\Admin\LeaderboardController::class, 'index'])->name('admin.leaderboard');
    Route::post('/leaderboard/prizes', [App\Http\Controllers\Admin\LeaderboardController::class, 'savePrizes'])->name('admin.leaderboard.prizes');
    Route::post('/leaderboard/distribute', [App\Http\Controllers\Admin\LeaderboardController::class, 'distribute'])->name('admin.leaderboard.distribute');
    Route::get('/bonus',  [App\Http\Controllers\Admin\BonusController::class, 'index'])->name('admin.bonus');
    Route::get('/bonus/export',  [App\Http\Controllers\Admin\BonusController::class, 'export'])->name('admin.bonus.export');
    Route::post('/bonus',  [App\Http\Controllers\Admin\BonusController::class, 'add'])->name('admin.bonus.add');
    Route::post('/bonus/generate',  [App\Http\Controllers\Admin\BonusController::class, 'generate'])->name('admin.bonus.generate');
    Route::post('/bonus/bulk',  [App\Http\Controllers\Admin\BonusController::class, 'bulk'])->name('admin.bonus.bulk');
    Route::put('/bonus',  [App\Http\Controllers\Admin\BonusController::class, 'update'])->name('admin.bonus.update');
    Route::get('/bonus-history',  [App\Http\Controllers\Admin\BonusHistoryController::class, 'index'])->name('admin.bonus-history');
    Route::get('/settings', [App\Http\Controllers\Admin\SiteSettingsController::class, 'index'])->name('admin.settings');
    Route::post('/settings', [App\Http\Controllers\Admin\SiteSettingsController::class, 'update'])->name('admin.settings.update');
    Route::get('/users/{id}', [App\Http\Controllers\Admin\UsersViewController::class, 'index'])->name('admin.users.view');
    Route::post('/users/{id}', [App\Http\Controllers\Admin\UsersViewController::class, 'update'])->name('admin.users.update');
    Route::patch('/face-verifications/{faceVerification}', [App\Http\Controllers\Admin\FaceVerificationsController::class, 'update'])->name('admin.face-verifications.update');
});
