<?php

use App\Http\Controllers\Admin\AcademyController;
use App\Http\Controllers\Admin\AcademyScheduleController;
use App\Http\Controllers\Admin\AdminController;
use App\Http\Controllers\Admin\Auth\LoginController;
use App\Http\Controllers\Admin\BannerController;
use App\Http\Controllers\Admin\BookingController;
use App\Http\Controllers\Admin\ChampionshipController;
use App\Http\Controllers\Admin\ChampionshipGroupController;
use App\Http\Controllers\Admin\ChampionshipMatchController;
use App\Http\Controllers\Admin\ChampionshipTeamController;
use App\Http\Controllers\Admin\CityController;
use App\Http\Controllers\Admin\CoachController;
use App\Http\Controllers\Admin\ContractController;
use App\Http\Controllers\Admin\ContractSettingController;
use App\Http\Controllers\Admin\CountryController;
use App\Http\Controllers\Admin\CourtController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\DependentController;
use App\Http\Controllers\Admin\GameController;
use App\Http\Controllers\Admin\LanguageController;
use App\Http\Controllers\Admin\MemberController;
use App\Http\Controllers\Admin\NewsController;
use App\Http\Controllers\Admin\NotificationController;
use App\Http\Controllers\Admin\ParkingController;
use App\Http\Controllers\Admin\QrCodeController;
use App\Http\Controllers\Admin\QrSettingController;
use App\Http\Controllers\Admin\RoleController;
use App\Http\Controllers\Admin\SecurityController;
use App\Http\Controllers\Admin\SettingsController;
use App\Http\Controllers\Admin\SlotController;
use App\Http\Controllers\Admin\SubscriptionDurationController;
use App\Http\Controllers\Admin\SubscriptionTypeController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Admin\VisitorManagementController;
use Illuminate\Support\Facades\Route;

/*

<!-- php artisan make:crud BlogPost --fields="title:string,slug:string:unique,body:string:nullable,is_active:boolean:default" --translatable="title,body"
 -->
git fetch origin
git reset --hard origin/main

|--------------------------------------------------------------------------
| Admin Routes
|--------------------------------------------------------------------------
*/

Route::prefix('admin')->name('admin.')->group(function () {

    // Guest routes
    Route::middleware('guest.admin')->group(function () {
        Route::get('login', [LoginController::class, 'showLoginForm'])->name('login');
        Route::post('login', [LoginController::class, 'login'])->name('login.submit');
    });

    // Authenticated routes
    Route::middleware('admin')->group(function () {
        // Dashboard
        Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
        Route::post('logout', [LoginController::class, 'logout'])->name('logout');

        // Users Management
        Route::post('users/bulk-delete', [UserController::class, 'bulkDelete'])->name('users.bulkDelete');
        Route::post('users/bulk-status', [UserController::class, 'bulkStatus'])->name('users.bulkStatus');
        Route::post('users/status/{user}', [UserController::class, 'updateStatus'])->name('users.updateStatus');
        Route::get('users/datatable', [UserController::class, 'datatable'])->name('users.datatable');
        Route::resource('users', UserController::class);

        // Admins Management
        Route::post('admins/bulk-delete', [AdminController::class, 'bulkDelete'])->name('admins.bulkDelete');
        Route::post('admins/bulk-status', [AdminController::class, 'bulkStatus'])->name('admins.bulkStatus');
        Route::post('admins/status/{admin}', [AdminController::class, 'updateStatus'])->name('admins.updateStatus');
        Route::get('admins/datatable', [AdminController::class, 'datatable'])->name('admins.datatable');
        Route::resource('admins', AdminController::class);

        // Roles Management
        Route::post('roles/bulk-delete', [RoleController::class, 'bulkDelete'])->name('roles.bulkDelete');
        Route::get('roles/datatable', [RoleController::class, 'datatable'])->name('roles.datatable');
        Route::resource('roles', RoleController::class);

        // Countries Management
        Route::post('countries/bulk-delete', [CountryController::class, 'bulkDelete'])->name('countries.bulkDelete');
        Route::post('countries/bulk-status', [CountryController::class, 'bulkStatus'])->name('countries.bulkStatus');
        Route::post('countries/status/{country}', [CountryController::class, 'updateStatus'])->name('countries.updateStatus');
        Route::get('countries/datatable', [CountryController::class, 'datatable'])->name('countries.datatable');
        Route::get('countries/{country}/cities/datatable', [CountryController::class, 'citiesDatatable'])->name('countries.cities.datatable');
        Route::resource('countries', CountryController::class);

        // Cities Management
        Route::post('cities/bulk-delete', [CityController::class, 'bulkDelete'])->name('cities.bulkDelete');
        Route::post('cities/bulk-status', [CityController::class, 'bulkStatus'])->name('cities.bulkStatus');
        Route::post('cities/status/{city}', [CityController::class, 'updateStatus'])->name('cities.updateStatus');
        Route::get('cities/datatable', [CityController::class, 'datatable'])->name('cities.datatable');
        Route::resource('cities', CityController::class);

        // Languages Management
        Route::post('languages/bulk-delete', [LanguageController::class, 'bulkDelete'])->name('languages.bulkDelete');
        Route::post('languages/bulk-status', [LanguageController::class, 'bulkStatus'])->name('languages.bulkStatus');
        Route::post('languages/status/{language}', [LanguageController::class, 'updateStatus'])->name('languages.updateStatus');
        Route::get('languages/datatable', [LanguageController::class, 'datatable'])->name('languages.datatable');
        Route::resource('languages', LanguageController::class);

        // Subscription Types Management
        Route::post('subscription-types/bulk-delete', [SubscriptionTypeController::class, 'bulkDelete'])->name('subscription-types.bulkDelete');
        Route::post('subscription-types/bulk-status', [SubscriptionTypeController::class, 'bulkStatus'])->name('subscription-types.bulkStatus');
        Route::post('subscription-types/status/{subscription_type}', [SubscriptionTypeController::class, 'updateStatus'])->name('subscription-types.updateStatus');
        Route::get('subscription-types/datatable', [SubscriptionTypeController::class, 'datatable'])->name('subscription-types.datatable');
        Route::resource('subscription-types', SubscriptionTypeController::class);

        // Subscription Durations Management
        Route::post('subscription-durations/bulk-delete', [SubscriptionDurationController::class, 'bulkDelete'])->name('subscription-durations.bulkDelete');
        Route::post('subscription-durations/bulk-status', [SubscriptionDurationController::class, 'bulkStatus'])->name('subscription-durations.bulkStatus');
        Route::post('subscription-durations/status/{subscription_duration}', [SubscriptionDurationController::class, 'updateStatus'])->name('subscription-durations.updateStatus');
        Route::get('subscription-durations/datatable', [SubscriptionDurationController::class, 'datatable'])->name('subscription-durations.datatable');
        Route::resource('subscription-durations', SubscriptionDurationController::class);

        // Contract Settings Management
        Route::post('contract-settings/bulk-delete', [ContractSettingController::class, 'bulkDelete'])->name('contract-settings.bulkDelete');
        Route::post('contract-settings/bulk-status', [ContractSettingController::class, 'bulkStatus'])->name('contract-settings.bulkStatus');
        Route::post('contract-settings/status/{contract_setting}', [ContractSettingController::class, 'updateStatus'])->name('contract-settings.updateStatus');
        Route::get('contract-settings/datatable', [ContractSettingController::class, 'datatable'])->name('contract-settings.datatable');
        Route::resource('contract-settings', ContractSettingController::class);

        // Contracts Management
        Route::post('contracts/bulk-delete', [ContractController::class, 'bulkDelete'])->name('contracts.bulkDelete');
        Route::post('contracts/bulk-status', [ContractController::class, 'bulkStatus'])->name('contracts.bulkStatus');
        Route::post('contracts/status/{contract}', [ContractController::class, 'updateStatus'])->name('contracts.updateStatus');
        Route::get('contracts/datatable', [ContractController::class, 'datatable'])->name('contracts.datatable');
        Route::get('contracts/{contract}/pdf', [ContractController::class, 'exportPdf'])->name('contracts.pdf');
        Route::get('contracts/{contract}/print', [ContractController::class, 'print'])->name('contracts.print');
        Route::resource('contracts', ContractController::class);

        // Visitor Managements
        Route::post('visitor-managements/bulk-delete', [VisitorManagementController::class, 'bulkDelete'])->name('visitor-managements.bulkDelete');
        Route::post('visitor-managements/bulk-status', [VisitorManagementController::class, 'bulkStatus'])->name('visitor-managements.bulkStatus');
        Route::post('visitor-managements/status/{visitor_management}', [VisitorManagementController::class, 'updateStatus'])->name('visitor-managements.updateStatus');
        Route::get('visitor-managements/datatable', [VisitorManagementController::class, 'datatable'])->name('visitor-managements.datatable');
        Route::resource('visitor-managements', VisitorManagementController::class);

        // Securities
        Route::post('securities/bulk-delete', [SecurityController::class, 'bulkDelete'])->name('securities.bulkDelete');
        Route::post('securities/bulk-status', [SecurityController::class, 'bulkStatus'])->name('securities.bulkStatus');
        Route::post('securities/status/{security}', [SecurityController::class, 'updateStatus'])->name('securities.updateStatus');
        Route::get('securities/datatable', [SecurityController::class, 'datatable'])->name('securities.datatable');
        Route::resource('securities', SecurityController::class);

        // QR Codes Management (admin view only)
        Route::post('qr-codes/bulk-delete', [QrCodeController::class, 'bulkDelete'])->name('qr-codes.bulkDelete');
        Route::post('qr-codes/bulk-status', [QrCodeController::class, 'bulkStatus'])->name('qr-codes.bulkStatus');
        Route::post('qr-codes/status/{qr_code}', [QrCodeController::class, 'updateStatus'])->name('qr-codes.updateStatus');
        Route::get('qr-codes/member-scans/datatable', [QrCodeController::class, 'memberScansDatatable'])->name('qr-codes.member-scans.datatable');
        Route::get('qr-codes/member-scans', [QrCodeController::class, 'memberScans'])->name('qr-codes.member-scans.index');
        Route::get('qr-codes/member-scans/{member_access_log}', [QrCodeController::class, 'showMemberScan'])->name('qr-codes.member-scans.show');
        Route::get('qr-codes/datatable', [QrCodeController::class, 'datatable'])->name('qr-codes.datatable');
        Route::resource('qr-codes', QrCodeController::class)->only(['index', 'show', 'destroy']);

        // Members Management
        Route::post('members/bulk-delete', [MemberController::class, 'bulkDelete'])->name('members.bulkDelete');
        Route::post('members/bulk-status', [MemberController::class, 'bulkStatus'])->name('members.bulkStatus');
        Route::post('members/status/{member}', [MemberController::class, 'updateStatus'])->name('members.updateStatus');
        Route::post('members/notifications/specific', [NotificationController::class, 'sendSpecific'])->name('members.notifications.send');
        Route::get('members/export', [MemberController::class, 'export'])->name('members.export');
        Route::get('members/import', [MemberController::class, 'importPage'])->name('members.import.page');
        Route::get('members/import/template', [MemberController::class, 'downloadTemplate'])->name('members.import.template');
        Route::post('members/import', [MemberController::class, 'import'])->name('members.import');
        Route::get('members/datatable', [MemberController::class, 'datatable'])->name('members.datatable');
        Route::resource('members', MemberController::class);
        Route::get('members/notification/{member}', [MemberController::class, 'get_notification'])->name('members.get-notification');

        // Notifications Management
        Route::get('send-notifications', [NotificationController::class, 'index'])->name('notifications.index');
        Route::post('send-notifications/general', [NotificationController::class, 'sendGeneral'])->name('notifications.sendGeneral');
        Route::get('send-notifications/members-options', [NotificationController::class, 'membersOptions'])->name('notifications.membersOptions');
        Route::get('send-notifications/coaches-options', [NotificationController::class, 'coachesOptions'])->name('notifications.coachesOptions');

        // Specific Coach Notification
        Route::post('coaches/notifications/specific', [NotificationController::class, 'sendSpecificCoach'])->name('coaches.notifications.send');

        // Dependents Management
        Route::post('dependents/bulk-delete', [DependentController::class, 'bulkDelete'])->name('dependents.bulkDelete');
        Route::post('dependents/bulk-status', [DependentController::class, 'bulkStatus'])->name('dependents.bulkStatus');
        Route::post('dependents/status/{dependent}', [DependentController::class, 'updateStatus'])->name('dependents.updateStatus');
        Route::get('dependents/export', [DependentController::class, 'export'])->name('dependents.export');
        Route::get('dependents/import', [DependentController::class, 'importPage'])->name('dependents.import.page');
        Route::get('dependents/import/template', [DependentController::class, 'downloadTemplate'])->name('dependents.import.template');
        Route::post('dependents/import', [DependentController::class, 'import'])->name('dependents.import');
        Route::get('dependents/datatable', [DependentController::class, 'datatable'])->name('dependents.datatable');
        Route::resource('dependents', DependentController::class);

        // Games Management
        Route::post('games/bulk-delete', [GameController::class, 'bulkDelete'])->name('games.bulkDelete');
        Route::post('games/bulk-status', [GameController::class, 'bulkStatus'])->name('games.bulkStatus');
        Route::post('games/status/{game}', [GameController::class, 'updateStatus'])->name('games.updateStatus');
        Route::get('games/datatable', [GameController::class, 'datatable'])->name('games.datatable');
        Route::resource('games', GameController::class);

        // Courts Management
        Route::post('courts/bulk-delete', [CourtController::class, 'bulkDelete'])->name('courts.bulkDelete');
        Route::post('courts/bulk-status', [CourtController::class, 'bulkStatus'])->name('courts.bulkStatus');
        Route::post('courts/status/{court}', [CourtController::class, 'updateStatus'])->name('courts.updateStatus');
        Route::get('courts/datatable', [CourtController::class, 'datatable'])->name('courts.datatable');
        Route::resource('courts', CourtController::class);

        // Bookings Management
        Route::post('bookings/bulk-delete', [BookingController::class, 'bulkDelete'])->name('bookings.bulkDelete');
        Route::post('bookings/bulk-status', [BookingController::class, 'bulkStatus'])->name('bookings.bulkStatus');
        Route::post('bookings/status/{booking}', [BookingController::class, 'updateStatus'])->name('bookings.updateStatus');
        Route::get('bookings/datatable', [BookingController::class, 'datatable'])->name('bookings.datatable');
        Route::resource('bookings', BookingController::class)->only(['index', 'show', 'destroy']);

        // Parkings Management
        Route::post('parkings/bulk-delete', [ParkingController::class, 'bulkDelete'])->name('parkings.bulkDelete');
        Route::post('parkings/bulk-status', [ParkingController::class, 'bulkStatus'])->name('parkings.bulkStatus');
        Route::post('parkings/status/{parking}', [ParkingController::class, 'updateStatus'])->name('parkings.updateStatus');
        Route::get('parkings/datatable', [ParkingController::class, 'datatable'])->name('parkings.datatable');
        Route::resource('parkings', ParkingController::class)->only(['index', 'show', 'destroy']);

        // Banners Management
        Route::post('banners/bulk-delete', [BannerController::class, 'bulkDelete'])->name('banners.bulkDelete');
        Route::post('banners/bulk-status', [BannerController::class, 'bulkStatus'])->name('banners.bulkStatus');
        Route::post('banners/status/{banner}', [BannerController::class, 'updateStatus'])->name('banners.updateStatus');
        Route::get('banners/datatable', [BannerController::class, 'datatable'])->name('banners.datatable');
        Route::resource('banners', BannerController::class);

        // Coaches Management
        Route::post('coaches/bulk-delete', [CoachController::class, 'bulkDelete'])->name('coaches.bulkDelete');
        Route::post('coaches/bulk-status', [CoachController::class, 'bulkStatus'])->name('coaches.bulkStatus');
        Route::post('coaches/status/{coach}', [CoachController::class, 'updateStatus'])->name('coaches.updateStatus');
        Route::get('coaches/datatable', [CoachController::class, 'datatable'])->name('coaches.datatable');
        Route::resource('coaches', CoachController::class);

        // Academies Management
        Route::post('academies/bulk-delete', [AcademyController::class, 'bulkDelete'])->name('academies.bulkDelete');
        Route::post('academies/bulk-status', [AcademyController::class, 'bulkStatus'])->name('academies.bulkStatus');
        Route::post('academies/status/{academy}', [AcademyController::class, 'updateStatus'])->name('academies.updateStatus');
        Route::get('academies/datatable', [AcademyController::class, 'datatable'])->name('academies.datatable');
        Route::get('academies/{academy}/members', [AcademyController::class, 'manageMembers'])->name('academies.members.index');
        Route::get('academies/{academy}/members/datatable', [AcademyController::class, 'membersDatatable'])->name('academies.members.datatable');
        Route::get('academies/{academy}/members/ids', [AcademyController::class, 'memberIds'])->name('academies.members.ids');
        Route::get('academies/{academy}/members/selected', [AcademyController::class, 'selectedMembers'])->name('academies.members.selected');
        Route::get('academies/{academy}/members/import', [AcademyController::class, 'importMembersPage'])->name('academies.members.import.page');
        Route::get('academies/{academy}/members/import/template', [AcademyController::class, 'downloadAcademyImportTemplate'])->name('academies.members.import.template');
        Route::get('academies/{academy}/members/import/template-legacy', [AcademyController::class, 'downloadAcademyImportLegacyTemplate'])->name('academies.members.import.template.legacy');
        Route::get('academies/{academy}/members/export/members', [AcademyController::class, 'exportAvailableMembers'])->name('academies.members.export.members');
        Route::get('academies/{academy}/members/export/dependents', [AcademyController::class, 'exportAvailableDependents'])->name('academies.members.export.dependents');
        Route::get('academies/{academy}/members/export/all', [AcademyController::class, 'exportAvailableAll'])->name('academies.members.export.all');
        Route::get('academies/{academy}/members/export-selected/members', [AcademyController::class, 'exportSelectedAssignedMembers'])->name('academies.members.export-selected.members');
        Route::get('academies/{academy}/members/export-selected/dependents', [AcademyController::class, 'exportSelectedAssignedDependents'])->name('academies.members.export-selected.dependents');
        Route::get('academies/{academy}/members/export-selected/all', [AcademyController::class, 'exportSelectedAssignedAll'])->name('academies.members.export-selected.all');
        Route::post('academies/{academy}/members/sync', [AcademyController::class, 'syncMembers'])->name('academies.members.sync');
        Route::post('academies/{academy}/members/export-selected', [AcademyController::class, 'exportSelectedMembers'])->name('academies.members.export-selected');
        Route::post('academies/{academy}/members/import', [AcademyController::class, 'importMembers'])->name('academies.members.import');
        Route::get('academies/{academy}/assigned-members/datatable', [AcademyController::class, 'assignedMembersDatatable'])->name('academies.assigned-members.datatable');
        Route::resource('academies', AcademyController::class);

        // Academy Schedules Management
        Route::get('academy-schedules/available-slots', [AcademyScheduleController::class, 'availableSlots'])->name('academy-schedules.availableSlots');
        Route::get('academy-schedules/courts-by-academy', [AcademyScheduleController::class, 'courtsByAcademy'])->name('academy-schedules.courtsByAcademy');
        Route::post('academy-schedules/bulk-delete', [AcademyScheduleController::class, 'bulkDelete'])->name('academy-schedules.bulkDelete');
        Route::post('academy-schedules/bulk-status', [AcademyScheduleController::class, 'bulkStatus'])->name('academy-schedules.bulkStatus');
        Route::post('academy-schedules/status/{academy_schedule}', [AcademyScheduleController::class, 'updateStatus'])->name('academy-schedules.updateStatus');
        Route::get('academy-schedules/datatable', [AcademyScheduleController::class, 'datatable'])->name('academy-schedules.datatable');
        Route::resource('academy-schedules', AcademyScheduleController::class);

        // Championships Management
        Route::post('championships/bulk-delete', [ChampionshipController::class, 'bulkDelete'])->name('championships.bulkDelete');
        Route::post('championships/bulk-status', [ChampionshipController::class, 'bulkStatus'])->name('championships.bulkStatus');
        Route::post('championships/status/{championship}', [ChampionshipController::class, 'updateStatus'])->name('championships.updateStatus');
        Route::get('championships/datatable', [ChampionshipController::class, 'datatable'])->name('championships.datatable');
        Route::get('championships/{championship}/teams', [ChampionshipController::class, 'getTeams'])->name('championships.teams');
        Route::get('championships/{championship}/matches/builder', [ChampionshipController::class, 'matchesBuilder'])->name('championships.matches.builder');
        Route::post('championships/{championship}/matches/bulk', [ChampionshipController::class, 'storeBulkMatches'])->name('championships.matches.bulk');
        Route::post('championships/{championship}/matches', [ChampionshipController::class, 'storeMatch'])->name('championships.matches.store');
        Route::put('championships/matches/{match}', [ChampionshipController::class, 'updateMatch'])->name('championships.matches.update');
        Route::post('championships/matches/{match}/result', [ChampionshipController::class, 'submitMatchResult'])->name('championships.matches.result');
        Route::delete('championships/matches/{match}', [ChampionshipController::class, 'destroyMatch'])->name('championships.matches.destroy');
        Route::resource('championships', ChampionshipController::class);

        // Championship Teams Management
        Route::get('championship-teams/datatable', [ChampionshipTeamController::class, 'datatable'])->name('championship-teams.datatable');
        Route::resource('championship-teams', ChampionshipTeamController::class);

        // Championship Matches Management
        Route::get('championship-matches/datatable', [ChampionshipMatchController::class, 'datatable'])->name('championship-matches.datatable');
        Route::post('championship-matches/{championship_match}/result', [ChampionshipMatchController::class, 'submitResult'])->name('championship-matches.result');
        Route::resource('championship-matches', ChampionshipMatchController::class);

        // Championship Groups Management
        Route::get('championship-groups/datatable', [ChampionshipGroupController::class, 'datatable'])->name('championship-groups.datatable');
        Route::resource('championship-groups', ChampionshipGroupController::class);

        // News Management
        Route::post('news/bulk-delete', [NewsController::class, 'bulkDelete'])->name('news.bulkDelete');
        Route::post('news/bulk-status', [NewsController::class, 'bulkStatus'])->name('news.bulkStatus');
        Route::post('news/status/{news}', [NewsController::class, 'updateStatus'])->name('news.updateStatus');
        Route::get('news/datatable', [NewsController::class, 'datatable'])->name('news.datatable');
        Route::resource('news', NewsController::class);

        // Slots Management (Bookings view as Slots)
        Route::get('slots/datatable', [SlotController::class, 'datatable'])->name('slots.datatable');
        Route::get('slots', [SlotController::class, 'index'])->name('slots.index');

        // QR Settings Management
        Route::post('qr-settings/bulk-delete', [QrSettingController::class, 'bulkDelete'])->name('qr-settings.bulkDelete');
        Route::post('qr-settings/bulk-status', [QrSettingController::class, 'bulkStatus'])->name('qr-settings.bulkStatus');
        Route::post('qr-settings/status/{qr_setting}', [QrSettingController::class, 'updateStatus'])->name('qr-settings.updateStatus');
        Route::get('qr-settings/datatable', [QrSettingController::class, 'datatable'])->name('qr-settings.datatable');
        Route::resource('qr-settings', QrSettingController::class);

        // Locale Switch
        Route::get('locale/{locale}', function (string $locale) {
            if (in_array($locale, ['en', 'ar'])) {
                session(['locale' => $locale]);
            }

            return redirect()->back();
        })->name('locale.switch');

        // Settings
        Route::prefix('settings')->name('settings.')->group(function () {
            Route::get('general', [SettingsController::class, 'general'])->name('general');
            Route::post('general', [SettingsController::class, 'updateGeneral'])->name('general.update');
            Route::get('profile', [SettingsController::class, 'profile'])->name('profile');
            Route::post('profile', [SettingsController::class, 'updateProfile'])->name('profile.update');
        });
    });
});
