<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Auth::routes();

Route::get('logout', [App\Http\Controllers\Auth\LoginController::class, 'logout'])->name('/')->middleware(['auth', 'close.session.early']);
Route::post('/logout-everywhere', [App\Http\Controllers\Auth\LoginController::class, 'logoutEverywhere'])->name('logout.everywhere')->middleware('auth');
Route::post('/security/client-error', [App\Http\Controllers\SecurityController::class, 'clientError'])->name('security.client_error');
Route::get('/security/unlock-account/{token}', [App\Http\Controllers\SecurityController::class, 'unlockAccount'])->name('security.unlock_account');

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home')->middleware(['auth', 'close.session.early']);

Route::get('/', [App\Http\Controllers\IndexController::class, 'index'])->name('/index');
Route::get('/index/regions', [App\Http\Controllers\IndexController::class, 'regions'])->name('/index/regions');
Route::get('/index/district', [App\Http\Controllers\IndexController::class, 'district'])->name('/index/district');

Route::get('/index/gender', [App\Http\Controllers\IndexController::class, 'gender'])->name('/index/gender');
Route::get('/index/age', [App\Http\Controllers\IndexController::class, 'age'])->name('/index/age');
Route::get('/index/disability', [App\Http\Controllers\IndexController::class, 'disability'])->name('/index/disability');

Route::get('/index/contact', [App\Http\Controllers\IndexController::class, 'contact'])->name('/contact');
//Route::get('/index/dashboard', [App\Http\Controllers\IndexController::class, 'dashboard'])->name('/dashboard')->middleware(['auth', 'close.session.early']);
Route::get('/index/resources', [App\Http\Controllers\IndexController::class, 'resources'])->name('/resources');
Route::get('/index/all', [App\Http\Controllers\IndexController::class, 'all'])->name('/all');
Route::get('/index/mapdata', [App\Http\Controllers\IndexController::class, 'mapdata'])->name('/index/mapdata');
Route::get('/index/gender', [App\Http\Controllers\IndexController::class, 'gender'])->name('/gender');
Route::get('/index/age', [App\Http\Controllers\IndexController::class, 'age'])->name('/age');
Route::get('/index/pwd', [App\Http\Controllers\IndexController::class, 'pwd'])->name('/pwd');

Route::get('/dashboard', [App\Http\Controllers\DashboardController::class, 'index'])->name('/dashboard/index')->middleware(['auth', 'close.session.early']);
Route::get('/dashboard/charts', [App\Http\Controllers\DashboardController::class, 'incidentsbysex'])->name('/dashboard/charts')->middleware(['auth', 'close.session.early']);

//DataEntry
Route::get('/dataentry/index', [App\Http\Controllers\DataEntryController::class, 'index'])->name('/dataentry/index')->middleware(['auth', 'close.session.early']);
Route::get('/dataentry/list', [App\Http\Controllers\DataEntryController::class, 'list'])->name('/dataentry/list')->middleware(['auth', 'close.session.early']);
Route::get('/dataentry/report', [App\Http\Controllers\DataEntryController::class, 'caseReport'])->name('/dataentry/report')->middleware(['auth', 'close.session.early']);
Route::get('/dataentry/listdetails', [App\Http\Controllers\DataEntryController::class, 'listdetails'])->name('/dataentry/listdetails')->middleware(['auth', 'close.session.early']);
Route::get('/dataentry', [App\Http\Controllers\DataEntryController::class, 'index'])->name('/dataentry')->middleware(['auth', 'close.session.early']);
Route::get('/dataentry/import', [App\Http\Controllers\DataEntryController::class, 'import'])->name('/dataentry/import')->middleware(['auth', 'close.session.early']);
Route::post('/dataentry/import', [App\Http\Controllers\DataEntryController::class, 'processOfflineImport'])->name('/dataentry/import/process')->middleware('auth');
Route::get('/dataentry/import/template', [App\Http\Controllers\DataEntryController::class, 'downloadOfflineImportTemplate'])->name('/dataentry/import/template')->middleware(['auth', 'close.session.early']);
Route::get('/dataentry/profiledcases', [App\Http\Controllers\DataEntryController::class, 'profiledcases'])->name('/dataentry/profiledcases')->middleware(['auth', 'close.session.early']);

//Upadating incident records
Route::get('/dataentry/update', [App\Http\Controllers\DataEntryController::class, 'update'])->name('/dataentry/update')->middleware(['auth', 'close.session.early']);

Route::post('/dataentry/processvictimdata', [App\Http\Controllers\DataEntryController::class, 'processvictimdata'])->name('/dataentry/processvictimdata')->middleware('auth');
Route::post('/dataentry/processincidentdata', [App\Http\Controllers\DataEntryController::class, 'processincidentdata'])->name('/dataentry/processincidentdata')->middleware('auth');
Route::post('/dataentry/processperpetrator', [App\Http\Controllers\DataEntryController::class, 'processperpetrator'])->name('/dataentry/processperpetrator')->middleware('auth');
Route::post('/dataentry/processwitness', [App\Http\Controllers\DataEntryController::class, 'processwitness'])->name('/dataentry/processwitness')->middleware('auth');
Route::post('/dataentry/processaction', [App\Http\Controllers\DataEntryController::class, 'processaction'])->name('/dataentry/processaction')->middleware('auth');
Route::post('/dataentry/processstatus', [App\Http\Controllers\DataEntryController::class, 'processstatus'])->name('/dataentry/processstatus')->middleware('auth');

Route::post('/dataentry/updatevictimdata', [App\Http\Controllers\DataEntryController::class, 'updatevictimdata'])->name('/dataentry/updatevictimdata')->middleware('auth');
Route::post('/dataentry/updateincidentdata', [App\Http\Controllers\DataEntryController::class, 'updateincidentdata'])->name('/dataentry/updateincidentdata')->middleware('auth');
Route::post('/dataentry/updateperpetrator', [App\Http\Controllers\DataEntryController::class, 'updateperpetrator'])->name('/dataentry/updateperpetrator')->middleware('auth');
Route::post('/dataentry/updatewitness', [App\Http\Controllers\DataEntryController::class, 'updatewitness'])->name('/dataentry/updatewitness')->middleware('auth');
Route::post('/dataentry/updateaction', [App\Http\Controllers\DataEntryController::class, 'updateaction'])->name('/dataentry/updateaction')->middleware('auth');
Route::post('/dataentry/updatestatus', [App\Http\Controllers\DataEntryController::class, 'updatestatus'])->name('/dataentry/updatestatus')->middleware('auth');


Route::get('/dataentry/fgm', [App\Http\Controllers\DataEntryController::class, 'fgm'])->name('/dataentry/fgm')->middleware(['auth', 'close.session.early']);

//Settings
Route::get('/settings/', [App\Http\Controllers\SettingsController::class, 'index'])->name('/settings/index')->middleware(['auth', 'close.session.early']);
Route::post('/settings/update', [App\Http\Controllers\SettingsController::class, 'update'])->name('/settings/update')->middleware('auth');
Route::post('/settings/theme', [App\Http\Controllers\SettingsController::class, 'saveTheme'])->name('/settings/theme')->middleware('auth');
Route::post('/settings/theme/reset', [App\Http\Controllers\SettingsController::class, 'resetTheme'])->name('/settings/theme/reset')->middleware('auth');
Route::get('/resources/', [App\Http\Controllers\SettingsController::class, 'resources'])->name('/resources/index')->middleware(['auth', 'close.session.early']);
Route::post('/resources/postresource', [App\Http\Controllers\SettingsController::class, 'postresource'])->name('/resources/postresource')->middleware('auth');
Route::get('/resource/downloadfile/{resourceID}', [App\Http\Controllers\SettingsController::class, 'downloadFile'])->name('/resource/downloadfile/{resourceID}')->middleware(['auth', 'close.session.early']);
Route::get('/tracking/deleteevidence/{resourceID}', [App\Http\Controllers\SettingsController::class, 'deleteEvidence'])->name('/tracking/deleteevidence/{resourceID}')->middleware(['auth', 'close.session.early']);

//Location Settings
// ================= Location Settings =================
Route::middleware(['auth', 'close.session.early'])->prefix('location')->group(function () {

    // Nationality
    Route::get('/nationality', [App\Http\Controllers\LocationController::class, 'nationality'])->name('location.nationality');
    Route::post('/nationality', [App\Http\Controllers\LocationController::class, 'postnationality'])->name('location.nationality.post');
    Route::get('/nationality/{id}', [App\Http\Controllers\LocationController::class, 'getNationality'])->name('location.nationality.show');

    // Region
    Route::get('/regions', [App\Http\Controllers\LocationController::class, 'region'])->name('location.region');
    Route::post('/regions/store', [App\Http\Controllers\LocationController::class, 'storeRegion'])->name('location.region.store');
    Route::get('/regions/update/{id}', [App\Http\Controllers\LocationController::class, 'getRegion'])->name('location.region.edit');
    Route::get('/regions/{id}', [App\Http\Controllers\LocationController::class, 'getRegion'])->name('location.region.show');
    Route::post('/regions/update/{id}', [App\Http\Controllers\LocationController::class, 'updateRegion'])->name('location.region.update');
    Route::delete('/regions/delete/{id}', [App\Http\Controllers\LocationController::class, 'deleteRegion'])->name('location.region.delete');

    // District
    Route::get('/districts', [App\Http\Controllers\LocationController::class, 'district'])->name('location.district');
    Route::post('/districts/store', [App\Http\Controllers\LocationController::class, 'storeDistrict'])->name('location.district.store');
    Route::get('/districts/update/{id}', [App\Http\Controllers\LocationController::class, 'getDistrict'])->name('location.district.edit');
    Route::get('/districts/{id}', [App\Http\Controllers\LocationController::class, 'getDistrict'])->name('location.district.show');
    Route::post('/districts/update/{id}', [App\Http\Controllers\LocationController::class, 'updateDistrict'])->name('location.district.update');
    Route::delete('/districts/delete/{id}', [App\Http\Controllers\LocationController::class, 'deleteDistrict'])->name('location.district.delete');

    // SubCounty
    Route::get('/sub-county', [App\Http\Controllers\LocationController::class, 'subcounty'])->name('location.subcounty');
    Route::post('/sub-county/store', [App\Http\Controllers\LocationController::class, 'storeSubCounty'])->name('location.subcounty.store');
    Route::get('/sub-county/update/{id}', [App\Http\Controllers\LocationController::class, 'getSubCounty'])->name('location.subcounty.edit');
    Route::get('/sub-county/{id}', [App\Http\Controllers\LocationController::class, 'getSubCounty'])->name('location.subcounty.show');
    Route::post('/sub-county/update/{id}', [App\Http\Controllers\LocationController::class, 'updateSubCounty'])->name('location.subcounty.update');
    Route::delete('/sub-county/delete/{id}', [App\Http\Controllers\LocationController::class, 'deleteSubCounty'])->name('location.subcounty.delete');

    // Parish
    Route::get('/parish', [App\Http\Controllers\LocationController::class, 'parish'])->name('location.parish');
    Route::post('/parish/store', [App\Http\Controllers\LocationController::class, 'storeParish'])->name('location.parish.store');
    Route::get('/parish/update/{id}', [App\Http\Controllers\LocationController::class, 'getParish'])->name('location.parish.edit');
    Route::get('/parish/{id}', [App\Http\Controllers\LocationController::class, 'getParish'])->name('location.parish.show');
    Route::post('/parish/update/{id}', [App\Http\Controllers\LocationController::class, 'updateParish'])->name('location.parish.update');
    Route::delete('/parish/delete/{id}', [App\Http\Controllers\LocationController::class, 'deleteParish'])->name('location.parish.delete');

    // List locations dynamically
    Route::get('/list/{locationType}', [App\Http\Controllers\LocationController::class, 'list'])->name('location.list');
});

//IndicatorSettings
Route::get('/indicator/incidents', [App\Http\Controllers\IndicatorController::class, 'incidents'])->name('/indicator/incidents')->middleware(['auth', 'close.session.early']); //Incident Categories page
Route::post('/indicator/processincident', [App\Http\Controllers\IndicatorController::class, 'processincident'])->name('/indicator/processincident')->middleware('auth'); //Incident Categories Post
Route::post('/indicator/updateincident', [App\Http\Controllers\IndicatorController::class, 'updateincident'])->name('/indicator/updateincident')->middleware('auth'); //Incident Categories Post
Route::get('/indicator/list', [App\Http\Controllers\IndicatorController::class, 'list'])->name('/indicator/list')->middleware(['auth', 'close.session.early']); //Indicator listing

Route::get('/indicator/agegroups', [App\Http\Controllers\IndicatorController::class, 'agegroup'])->name('/indicator/agegroups')->middleware(['auth', 'close.session.early']); //Age group page
Route::post('/indicator/processage', [App\Http\Controllers\IndicatorController::class, 'processage'])->name('/indicator/processage')->middleware('auth'); //Age group save
Route::post('/indicator/updateagegroups', [App\Http\Controllers\IndicatorController::class, 'updateagegroups'])->name('/indicator/updateagegroups')->middleware('auth'); //Age group update
Route::get('/indicator/disableage', [App\Http\Controllers\IndicatorController::class, 'disableage'])->name('/indicator/disableage')->middleware(['auth', 'close.session.early']); //Age group update

//Gender Indicator
Route::get('/indicator/gender', [App\Http\Controllers\IndicatorController::class, 'gender'])->name('/indicator/gender')->middleware(['auth', 'close.session.early']); //Gender Page
Route::post('/indicator/processgender', [App\Http\Controllers\IndicatorController::class, 'processgender'])->name('/indicator/processgender')->middleware('auth'); //Gender Save
Route::post('/indicator/updategender', [App\Http\Controllers\IndicatorController::class, 'updategender'])->name('/indicator/updategender')->middleware('auth'); //Gender update

//Religion Indicator
Route::get('/indicator/religion', [App\Http\Controllers\IndicatorController::class, 'religion'])->name('/indicator/religion')->middleware(['auth', 'close.session.early']); //Religion Page
Route::post('/indicator/processreligion', [App\Http\Controllers\IndicatorController::class, 'processreligion'])->name('/indicator/processreligion')->middleware('auth'); //Religion Save
Route::post('/indicator/updatereligion', [App\Http\Controllers\IndicatorController::class, 'updatereligion'])->name('/indicator/updatereligion')->middleware('auth'); //Religion update
Route::get('/indicator/disablereligion', [App\Http\Controllers\IndicatorController::class, 'disablereligion'])->name('/indicator/disablereligion')->middleware(['auth', 'close.session.early']); //Religion update

//Relations Indicator
Route::get('/indicator/relations', [App\Http\Controllers\IndicatorController::class, 'relations'])->name('/indicator/relations')->middleware(['auth', 'close.session.early']); //Relations Page
Route::post('/indicator/processrelations', [App\Http\Controllers\IndicatorController::class, 'processrelations'])->name('/indicator/processrelations')->middleware('auth'); //Relations Save
Route::post('/indicator/updaterelations', [App\Http\Controllers\IndicatorController::class, 'updaterelations'])->name('/indicator/updaterelations')->middleware('auth'); //Relations update
Route::get('/indicator/disablerelations', [App\Http\Controllers\IndicatorController::class, 'disablerelations'])->name('/indicator/disablerelations')->middleware(['auth', 'close.session.early']); //Religion update

//Time of Day Indicator
Route::get('/indicator/timeofday', [App\Http\Controllers\IndicatorController::class, 'timeofday'])->name('/indicator/timeofday')->middleware(['auth', 'close.session.early']); //Time of Day Page
Route::post('/indicator/processtimeofday', [App\Http\Controllers\IndicatorController::class, 'processtimeofday'])->name('/indicator/processtimeofday')->middleware('auth'); //Time of Day Save
Route::post('/indicator/updatetimeofday', [App\Http\Controllers\IndicatorController::class, 'updatetimeofday'])->name('/indicator/updatetimeofday')->middleware('auth'); //Time of Day update
Route::get('/indicator/disabletime', [App\Http\Controllers\IndicatorController::class, 'disabletime'])->name('/indicator/disabletime')->middleware(['auth', 'close.session.early']); //Time of day update

//Marital Status Indicator
Route::get('/indicator/maritalstatus', [App\Http\Controllers\IndicatorController::class, 'maritalstatus'])->name('/indicator/maritalstatus')->middleware(['auth', 'close.session.early']); //Marital Status Page
Route::post('/indicator/processmaritalstatus', [App\Http\Controllers\IndicatorController::class, 'processmaritalstatus'])->name('/indicator/processmaritalstatus')->middleware('auth'); //Marital Status Save
Route::post('/indicator/updatemaritalstatus', [App\Http\Controllers\IndicatorController::class, 'updatemaritalstatus'])->name('/indicator/updatemaritalstatus')->middleware('auth'); //Marital Status update
Route::get('/indicator/disablemariage', [App\Http\Controllers\IndicatorController::class, 'disablemariage'])->name('/indicator/disablemariage')->middleware(['auth', 'close.session.early']); //Marriage of day update

//National Status Indicator
Route::get('/indicator/nationalstatus', [App\Http\Controllers\IndicatorController::class, 'nationalstatus'])->name('/indicator/nationalstatus')->middleware(['auth', 'close.session.early']); //Time of Day Page
Route::post('/indicator/processnationalstatus', [App\Http\Controllers\IndicatorController::class, 'processnationalstatus'])->name('/indicator/processnationalstatus')->middleware('auth'); //Time of Day Save
Route::post('/indicator/updatenationalstatus', [App\Http\Controllers\IndicatorController::class, 'updatenationalstatus'])->name('/indicator/updatenationalstatus')->middleware('auth'); //Time of Day update
Route::get('/indicator/disablenationalstatus', [App\Http\Controllers\IndicatorController::class, 'disablenationalstatus'])->name('/indicator/disablenationalstatus')->middleware(['auth', 'close.session.early']); //National Status update

//Disability Category
Route::get('/indicator/disability', [App\Http\Controllers\IndicatorController::class, 'disability'])->name('/indicator/disability')->middleware(['auth', 'close.session.early']); //Disability Category
Route::post('/indicator/processdisability', [App\Http\Controllers\IndicatorController::class, 'processdisability'])->name('/indicator/processdisability')->middleware('auth'); //Disability Category
Route::post('/indicator/updatedisability', [App\Http\Controllers\IndicatorController::class, 'updatedisability'])->name('/indicator/updatedisability')->middleware('auth'); //Disability Category
Route::get('/indicator/disabledisabiliy', [App\Http\Controllers\IndicatorController::class, 'disabledisabiliy'])->name('/indicator/disabledisabiliy')->middleware(['auth', 'close.session.early']); //Disability update

//Partner Listting and registration
Route::get('/partner/list', [App\Http\Controllers\PartnerController::class, 'list'])->name('/partner/list')->middleware(['auth', 'close.session.early']);
Route::get('/partner/index', [App\Http\Controllers\PartnerController::class, 'index'])->name('/partner/index')->middleware(['auth', 'close.session.early']);
Route::post('/partner/process', [App\Http\Controllers\PartnerController::class, 'process'])->name('/partner/process')->middleware('auth');
Route::post('/partner/update', [App\Http\Controllers\PartnerController::class, 'update'])->name('/partner/update')->middleware('auth');

Route::get('/partner/services', [App\Http\Controllers\PartnerController::class, 'service'])->name('/partner/services')->middleware(['auth', 'close.session.early']);
Route::get('/partner/servicelist', [App\Http\Controllers\PartnerController::class, 'services'])->name('/partner/servicelist')->middleware(['auth', 'close.session.early']);
Route::post('/partner/processservice', [App\Http\Controllers\PartnerController::class, 'process_service'])->name('/partner/processservice')->middleware('auth');

//Partner Category
Route::get('/partner/categorylist', [App\Http\Controllers\PartnerController::class, 'categorylist'])->name('/partner/categorylist')->middleware(['auth', 'close.session.early']);
Route::get('/partner/category', [App\Http\Controllers\PartnerController::class, 'category'])->name('/partner/category')->middleware(['auth', 'close.session.early']);
Route::post('/partner/processcategory', [App\Http\Controllers\PartnerController::class, 'processcategory'])->name('/partner/processcategory')->middleware('auth');
Route::post('/partner/updatecategory', [App\Http\Controllers\PartnerController::class, 'updatecategory'])->name('/partner/updatecategory')->middleware('auth');

//Adding the CRUD for adding License Keys
Route::get('/config/keys', [App\Http\Controllers\ConfigurationController::class, 'index'])->name('/config/keys')->middleware(['auth', 'close.session.early']);
Route::post('config/key/save', [App\Http\Controllers\ConfigurationController::class, 'savekey'])->name('license-keys.store')->middleware('auth');

//Analysis Loader
Route::get('/analysis/', [App\Http\Controllers\AnalysisController::class, 'index'])->name('/analysis/')->middleware(['auth', 'close.session.early']); //Time of Day Page
Route::get('/analysis/anaylsisdata', [App\Http\Controllers\AnalysisController::class, 'anaylsisdata'])->name('/analysis/anaylsisdata')->middleware(['auth', 'close.session.early']); //Time of Day Page

//Analysis my data Loader
Route::get('/analysis/mine', [App\Http\Controllers\AnalysisController::class, 'mine'])->name('/analysis/mine')->middleware(['auth', 'close.session.early']); //
Route::get('/analysis/myanaylsisdata', [App\Http\Controllers\AnalysisController::class, 'myanaylsisdata'])->name('/analysis/myanaylsisdata')->middleware(['auth', 'close.session.early']);

Route::get('/analysis/region', [App\Http\Controllers\AnalysisController::class, 'region'])->name('/analysis/region')->middleware(['auth', 'close.session.early']);
Route::get('/analysis/districtanaylsisdata', [App\Http\Controllers\AnalysisController::class, 'districtanaylsisdata'])->name('/analysis/districtanaylsisdata')->middleware(['auth', 'close.session.early']);
//Analysis Specific Indicators
Route::any('/analysis/indicator', [App\Http\Controllers\AnalysisController::class, 'indicator'])->name('/analysis/indicator')->middleware('auth'); //
Route::any('/analysis/indicator/{gender}', [App\Http\Controllers\AnalysisController::class, 'gender'])->name('/indicator/{gender}')->middleware('auth'); //


//Ministry and DCDO user registration

Route::get('/users/index', [App\Http\Controllers\UserMgtController::class, 'index'])->name('/users/index')->middleware(['auth', 'close.session.early']);
Route::post('/users/processuser', [App\Http\Controllers\UserMgtController::class, 'processuser'])->name('/users/processuser')->middleware('auth');

Route::any('/users/changestatus/{userid}/{status}', [App\Http\Controllers\UserMgtController::class, 'changestatus'])->name('/users/changestatus/{userid}/{status}')->middleware('auth');

Route::post('/users/createpartner', [App\Http\Controllers\UserMgtController::class, 'createpartner'])->name('/users/createpartner')->middleware('auth');
//Return Districts if not Admin
Route::get('/findDistrict', [App\Http\Controllers\DropdownController::class, 'findDistrict'])->name('/findDistrict')->middleware(['auth', 'close.session.early']);
Route::get('/findPartner', [App\Http\Controllers\DropdownController::class, 'findPartner'])->name('/findPartner')->middleware(['auth', 'close.session.early']);

//Creating of Partner accounts
Route::get('/users/partners', [App\Http\Controllers\UserMgtController::class, 'partners'])->name('/users/partners')->middleware(['auth', 'close.session.early']);

Route::post('/users/create', [App\Http\Controllers\UserMgtController::class, 'processuser'])->name('/users/create')->middleware('auth');
Route::post('/users/createparner', [App\Http\Controllers\UserMgtController::class, 'createparner'])->name('/users/createparner')->middleware('auth');
Route::get('/users/viewusers', [App\Http\Controllers\UserMgtController::class, 'viewusers'])->name('/users/viewusers')->middleware(['auth', 'close.session.early']);
Route::any('/users/updatepassword', [App\Http\Controllers\UserMgtController::class, 'updatepassword'])->name('/users/updatepassword')->middleware('auth');

//User Roles & Permissions
Route::get('/roles/list', [App\Http\Controllers\UserMgtController::class, 'userroles'])->name('/roles/list')->middleware(['auth', 'close.session.early']);
Route::post('/roles/permissions', [App\Http\Controllers\UserMgtController::class, 'saveRolePermissions'])->name('/roles/permissions')->middleware('auth');
Route::get('/roles/permissions/{roleKey}', [App\Http\Controllers\UserMgtController::class, 'configurePermissions'])->name('/roles/permissions/configure')->middleware(['auth', 'close.session.early']);
Route::post('/roles/permissions/{roleKey}', [App\Http\Controllers\UserMgtController::class, 'saveRolePermissionsForRole'])->name('/roles/permissions/save')->middleware('auth');
Route::get('/roles/index', [App\Http\Controllers\UserMgtController::class, 'roles'])->name('/roles/index')->middleware(['auth', 'close.session.early']);
Route::post('/roles/save', [App\Http\Controllers\UserMgtController::class, 'saveRole'])->name('/roles/save')->middleware('auth');

//Dropdown Lists
Route::get('/findSubcounty', [App\Http\Controllers\DropdownController::class, 'findSubcounty'])->name('/findSubcounty')->middleware(['auth', 'close.session.early']);
Route::get('/findParish', [App\Http\Controllers\DropdownController::class, 'findParish'])->name('/findParish')->middleware(['auth', 'close.session.early']);
Route::get('/findVillage', [App\Http\Controllers\DropdownController::class, 'findVillage'])->name('/findVillage')->middleware(['auth', 'close.session.early']);
Route::get('/findDisability', [App\Http\Controllers\DropdownController::class, 'findDisability'])->name('/findDisability')->middleware(['auth', 'close.session.early']);
Route::get('/findStatuses', [App\Http\Controllers\DropdownController::class, 'findStatuses'])->name('/findStatuses')->middleware(['auth', 'close.session.early']);
Route::get('/findSatisfaction', [App\Http\Controllers\DropdownController::class, 'findSatisfaction'])->name('/findSatisfaction')->middleware(['auth', 'close.session.early']);
Route::get('/findNSCategory', [App\Http\Controllers\DropdownController::class, 'findNSCategory'])->name('/findNSCategory')->middleware(['auth', 'close.session.early']);


//Route::get('/findSubcounty', [App\Http\Controllers\DropdownController::class, 'findSubcounty'])->name('/findSubcounty')->middleware(['auth', 'close.session.early']);
Route::get('/usercredentials', [App\Http\Controllers\DropdownController::class, 'usercredentials'])->name('/usercredentials')->middleware(['auth', 'close.session.early']);

//API Data

// API v1 routes are defined in routes/api.php.

Route::any('/download/index', [App\Http\Controllers\DownloadController::class, 'index'])->name('/download/index')->middleware('auth');
Route::any('/download/pdf', [App\Http\Controllers\DownloadController::class, 'pdf'])->name('/download/pdf')->middleware('auth');
Route::any('/exportToExcel', [App\Http\Controllers\DownloadController::class, 'exportToExcel'])->name('exportToExcel')->middleware('auth');

//Download of Data from Excel
Route::any('/download/excel', [App\Http\Controllers\DownloadController::class, 'excel'])->name('/download/excel')->middleware('auth');


//Error Handling
Route::get('/error/unknownpage', [App\Http\Controllers\ErrorHandlingController::class, 'missingpage'])->name('/error/unknownpage');
Route::get('/error/access', [App\Http\Controllers\ErrorHandlingController::class, 'access'])->name('/error/access');
Route::get('/error/500', [App\Http\Controllers\ErrorHandlingController::class, 'fatalError'])->name('/error/500');


// ================= API Integration Management =================
Route::middleware(['auth'])->prefix('integrations')->group(function () {
    Route::get('/', [App\Http\Controllers\IntegrationController::class, 'index'])->name('integrations.index');
    Route::get('/api-urls', [App\Http\Controllers\IntegrationController::class, 'apiUrls'])->name('integrations.api_urls');
    Route::get('/api-clients', [App\Http\Controllers\IntegrationController::class, 'apiClients'])->name('integrations.api_clients');
    Route::post('/api-clients', [App\Http\Controllers\IntegrationController::class, 'storeApiClient'])->name('integrations.api_clients.store');
    Route::put('/api-clients/{uuid}', [App\Http\Controllers\IntegrationController::class, 'updateApiClient'])->name('integrations.api_clients.update');
    Route::get('/logs', [App\Http\Controllers\IntegrationController::class, 'logs'])->name('integrations.logs');
    Route::get('/logs/{uuid}', [App\Http\Controllers\IntegrationController::class, 'logDetail'])->name('integrations.logs.show');
});

Route::get('/reports/verify', [App\Http\Controllers\ReportVerificationController::class, 'verify'])
    ->name('reports.verify');

// ================= System Audit Logs =================
Route::middleware(['auth'])->prefix('audit')->group(function () {
    Route::get('/logs', [App\Http\Controllers\AuditLogController::class, 'index'])->name('audit.logs');
    Route::get('/logs/export', [App\Http\Controllers\AuditLogController::class, 'export'])->name('audit.logs.export');
    Route::get('/logs/{uuid}', [App\Http\Controllers\AuditLogController::class, 'show'])->name('audit.logs.show');
});
