<?php

use Illuminate\Support\Facades\App;

Route::get('errors', 'V2\Dashboard\GeneralController@errors');

Route::get('/dashboard', function () {
    return view('version2.dashboard');
})->name('v2.dashboard');

Route::get('/', function () {
    return redirect(route('v2.dashboard'));
});

Route::get('/contact_us', function () {
    return view('version2.contact_us');
})->name('v2.contact_us');

// General APIs that doesn't fall under any category
Route::get('activity_statistics', 'V2\Dashboard\GeneralController@getActivityStatistics');

Route::get('get_otp_token', 'V2\Dashboard\OtpController@getOtpToken');
Route::post('verify_otp', 'V2\Dashboard\OtpController@verifyOtp');

Route::get('/items', 'V2\Dashboard\GeneralController@getItems');
Route::get('/sub_items/{item}', 'V2\Dashboard\GeneralController@getSubItems');

Route::prefix('contract')->group(function () {
    Route::get('/{contract}/unserialize', 'V2\Dashboard\ContractController@unserialize')->name('v2.contract.unserialize');
    Route::get('/report/map', 'V2\Dashboard\ContractController@getAllDataToMap')->name('v2.contract.report.map');
    Route::get('/{contract}', 'V2\Dashboard\ContractController@detail')->name('v2.contract.detail');
});

Route::prefix('road_items')->group(function () {
    Route::prefix('supervisor/cartable')->group(function () {
        Route::get('/', 'V2\Dashboard\RoadItemsProjectController@supervisorCartable')->name('v2.road_items.supervisor.cartable');
        Route::get('/show', 'V2\Dashboard\RoadItemsProjectController@supervisorShow');
        Route::get('/report', 'V2\Dashboard\RoadItemsProjectController@supervisorCartableReport');
        Route::post('/verify/{road_item}', 'V2\Dashboard\RoadItemsProjectController@verifyBySupervisor');
        Route::post('/restore/{road_item}', 'V2\Dashboard\RoadItemsProjectController@restore');
        Route::post('/delete/{road_item}', 'V2\Dashboard\RoadItemsProjectController@delete');
    });

    Route::prefix('operator/cartable')->group(function () {
        Route::get('/', 'V2\Dashboard\RoadItemsProjectController@operatorCartable')->name('v2.road_items.operator.cartable');
        Route::get('/show', 'V2\Dashboard\RoadItemsProjectController@operatorShow');
        Route::get('/report', 'V2\Dashboard\RoadItemsProjectController@operatorCartableReport');
    });

    Route::prefix('operator')->group(function () {
        Route::get('/create', 'V2\Dashboard\RoadItemsProjectController@operatorCreateView')->name('v2.road_items.operator.create');
        Route::post('/store', 'V2\Dashboard\RoadItemsProjectController@store');
        Route::post('/update/{road_item}', 'V2\Dashboard\RoadItemsProjectController@update');
    });


    Route::prefix('report')->group(function () {
        Route::get('/', 'V2\Dashboard\RoadItemsReportController@index')->name('v2.road_items.reports');
        Route::get('/total-group-province', 'V2\Dashboard\RoadItemsReportController@excel1');
        Route::get('/total-group-province-city', 'V2\Dashboard\RoadItemsReportController@excel1_city');
        Route::get('/total-items-group-province', 'V2\Dashboard\RoadItemsReportController@get_items');
        Route::get('/total-items-group-province-city', 'V2\Dashboard\RoadItemsReportController@get_items_city');
        Route::get('/map', 'V2\Dashboard\RoadItemsReportController@map');
    });

});

Route::prefix('road_patrols')->group(function () {
    Route::prefix('supervisor/cartable')->group(function () {
        Route::get('/', 'V2\Dashboard\RoadPatrolProjectController@supervisorCartable')->name('v2.road_patrols.supervisor.cartable');
        Route::get('/show', 'V2\Dashboard\RoadPatrolProjectController@supervisorShow');
        Route::get('/report', 'V2\Dashboard\RoadPatrolProjectController@supervisorCartableReport');
        Route::post('/verify/{road_patrol}', 'V2\Dashboard\RoadPatrolProjectController@verifyBySupervisor');
        Route::post('/delete/{road_patrol}', 'V2\Dashboard\RoadPatrolProjectController@delete');
        // Route::post('/complete_delete/{road_patrol}', 'V2\Dashboard\RoadPatrolProjectController@completeDelete');
    });

    Route::prefix('operator/cartable')->group(function () {
        Route::get('/', 'V2\Dashboard\RoadPatrolProjectController@operatorCartable')->name('v2.road_patrols.operator.cartable');
        Route::get('/show', 'V2\Dashboard\RoadPatrolProjectController@operatorShow');
        Route::get('/report', 'V2\Dashboard\RoadPatrolProjectController@operatorCartableReport');
    });

    Route::prefix('operator')->group(function () {
        Route::get('/create', 'V2\Dashboard\RoadPatrolProjectController@operatorCreateView')->name('v2.road_patrols.operator.create');
        Route::get('/report/{road_patrol}', 'V2\Dashboard\RoadPatrolProjectController@getReport')->name('v2.road_patrols.operator.report');
        Route::post('/store', 'V2\Dashboard\RoadPatrolProjectController@store');
    });


    Route::prefix('report')->group(function () {
        Route::get('/map', 'V2\Dashboard\RoadPatrolProjectController@getAllDataToMap')->name('v2.road_patrols.report.map');
        Route::get('/', 'V2\Dashboard\RoadPatrolReportController@index')->name('v2.road_patrol.reports');
        Route::get('/province_patrol_data', 'V2\Dashboard\RoadPatrolReportController@provincePatrolData');
        Route::get('/total-group-province-city', 'V2\Dashboard\RoadPatrolReportController@edarehPatrolData');
        Route::get('/total-items-group-province', 'V2\Dashboard\RoadPatrolReportController@get_items');
        Route::get('/total-items-group-province-city', 'V2\Dashboard\RoadPatrolReportController@get_items_city');
        Route::get('/excel', 'V2\Dashboard\RoadPatrolReportController@roadPatrolsReportTable');
        Route::get('/{road_patrol}', 'V2\Dashboard\RoadPatrolProjectController@detail')->name('v2.road_patrols.detail');

    });


});

Route::prefix('road_observations')->group(function () {
    Route::prefix('supervisor/cartable')->group(function () {
        Route::get('/', 'V2\Dashboard\RoadObservationController@supervisorCartable')->name('v2.road_observations.supervisor.cartable');
        Route::get('/show', 'V2\Dashboard\RoadObservationController@supervisorShow');
        Route::get('/report', 'V2\Dashboard\RoadObservationController@supervisorCartableReport');
        Route::post('/verify/{road_observed}', 'V2\Dashboard\RoadObservationController@verifyBySupervisor');
    });

    Route::prefix('operator/cartable')->group(function () {
        Route::get('/', 'V2\Dashboard\RoadObservationController@operatorCartable')->name('v2.road_observations.operator.cartable');
        // Route::get('/done', 'V2\Dashboard\RoadObservationController@showDone');
        Route::get('/report', 'V2\Dashboard\RoadObservationController@operatorCartableReport');
        Route::get('/show', 'V2\Dashboard\RoadObservationController@operatorShow');
    });

    // Route::get('/', 'V2\Dashboard\RoadObservationController@view')->name('v2.road_observations.operator');
    Route::get('/', 'V2\Dashboard\RoadObservationController@pendingView')->name('v2.road_observations.pending_view');
    Route::get('count', 'V2\Dashboard\RoadObservationController@count');
    Route::get('pending', 'V2\Dashboard\RoadObservationController@showPending');


    Route::get('{roadObserved}', 'V2\Dashboard\RoadObservationController@roadObserveDetail');

    Route::get('refer/list/{id}', 'V2\Dashboard\RoadObservationController@referList');
    Route::get('refer/report/{road_observed}', 'V2\Dashboard\RoadObservationController@referReport');
    Route::post('refer/{road_observed}', 'V2\Dashboard\RoadObservationController@refer');
    Route::post('/restore/{road_observed}', 'V2\Dashboard\RoadObservationController@restore');
    Route::post('handle/{road_observed}', 'V2\Dashboard\RoadObservationController@handle');

    Route::prefix('report')->group(function () {
        Route::get('/index', 'V2\Dashboard\RoadObservationReportController@index')->name('v2.road_observations.reports');
        Route::get('pending', 'V2\Dashboard\RoadObservationController@pendingReport');
        Route::get('/report', 'V2\Dashboard\RoadObservationController@report');
        Route::get('/map', 'V2\Dashboard\RoadPatrolProjectController@map')->name('v2.road_patrols.report.map');
        //  Route::get('/map', 'V2\Dashboard\RoadPatrolProjectController@getAllDataToMap')->name('v2.road_patrols.report.map');
        //  dd("rrr");
        Route::get('/report_table', 'V2\Dashboard\RoadObservationReportController@reportTable');
        Route::get('/total-group-province-city', 'V2\Dashboard\RoadObservationReportController@CityPatrolData');
        Route::get('/total-items-group-province', 'V2\Dashboard\RoadObservationReportController@get_items');
        Route::get('/total-items-group-province-city', 'V2\Dashboard\RoadObservationReportController@get_items_city');
        // Route::get('/{road_observations}', 'V2\Dashboard\RoadPatrolProjectController@detail')->name('v2.road_observationss.detail');
    });

    // Route::prefix('operator')->group(function () {
    //     Route::get('/create', 'V2\Dashboard\RoadObservationController@operatorCreateView')->name('v2.road_observations.operator.create');
    // });

    // Route::get('/add', 'V2\Dashboard\RoadObservationController@add');
    // Route::post('/store', 'V2\Dashboard\RoadObservationController@store');
});

Route::prefix('user_management')->group(function () {
    Route::get('/', 'V2\Dashboard\UserManagementController@index')->name('v2.user_management.list');
    Route::get('/activity_report', 'V2\Dashboard\UserManagementController@activityReport')->name('v2.user_management.activity_report');
});

Route::prefix('observed_items')->group(function () {
    Route::get('/', 'V2\Dashboard\ObservedItemController@searchByFilter');
    Route::get('/{observed_item}', 'V2\Dashboard\ObservedItemController@details');
});

Route::prefix('rahdari_projects')->group(function () {
    Route::get('proposal', function (Request $request) {
        return view('version2.dashboard_pages.rahdari_projects.proposal');
    })->name('v2.rahdari_projects.proposal');

    Route::get('finance', function (Request $request) {


        return view('version2.dashboard_pages.rahdari_projects.finance');
    })->name('v2.rahdari_projects.finance');

    Route::get('lawmakers', function (Request $request) {
        return view('version2.dashboard_pages.rahdari_projects.lawmakers');
    })->name('v2.rahdari_projects.lawmakers');

    Route::get('projects_list', function (Request $request) {
        return view('version2.dashboard_pages.rahdari_projects.projects_list');
    })->name('v2.rahdari_projects.projects_list');

    Route::get('project/{id}', function (Request $request) {
        return view('version2.dashboard_pages.rahdari_projects.project');
    })->name('v2.rahdari_projects.project');
});

Route::prefix('daily_accidents')->group(function () {
    Route::get('create', function (Request $request) {
        if (Auth::user()->can('add-accident') || Auth::user()->can('add-accident-province') || Auth::user()->can('accident-investigation') || Auth::user()->can('accident-investigation-province')) {
            return view('version2.dashboard_pages.accident_points.daily_accidents_create');
        }
        return abort(403);
    })->name('v2.daily_accidents.create');

    Route::get('map', function (Request $request) {
        return view('version2.dashboard_pages.accident_points.daily_accidents_map');
    })->name('v2.daily_accidents.map');
});

Route::prefix('winter_camp')->group(function () {
    Route::get('/', function (Request $request) {
        return view('version2.dashboard_pages.winter_camp.create');
    })->name('v2.winter_camp.create');

    // Route::get('/map/{id}', 'CampController@show_on_map');
    Route::get('/map/{id}', function (Request $request) {
        return view('version2.dashboard_pages.winter_camp.map');
    })->name('v2.winter_camp.map');
});

Route::prefix('rahdari_points')->group(function () {

    Route::get('/', function (Request $request) {
        if (Auth::user()->can('show-tollhouse') || Auth::user()->can('show-tollhouse-province')) {
            return view('version2.dashboard_pages.rahdari_points.create');
        }
        return abort(403);
    })->name('v2.rahdari_points.create');
});

Route::get('axis_reports', function (Request $request) {
    return view('version2.dashboard_pages.axis_reports');
})->name('v2.axis_reports');

Route::prefix('receipt')->group(function () {

    Route::prefix('/report')->group(function () {
        Route::get('', 'ReceiptReportController@index')->name('v2.receipt.report');
        Route::get('province-data', 'ReceiptReportController@provinceReceiptData');
        Route::get('city-data', 'ReceiptReportController@cityReceiptData');
        Route::get('/excel', 'ReceiptReportController@excelReport');

    });

    Route::get('', 'ReceiptController@view')->name('v2.receipt');
    Route::get('show', 'ReceiptController@show');
    Route::get('get-damages', 'ReceiptController@getDamages');
    Route::post('store', 'ReceiptController@store');
    Route::post('update/{accident}', 'ReceiptController@update');
    Route::post('delete/{accident}', 'ReceiptController@delete');
    Route::get('get-damages/{accident}', 'ReceiptController@getAccidentDamages');
    Route::get('{accident}', 'ReceiptController@details');

    Route::get('send-to-insurance/{accident}', 'ReceiptController@sendToInsurance');

    Route::post('upload-payment-info/{accident}', 'ReceiptController@uploadPaymentInfo');

    Route::post('invoice-bill/{accident}', 'ReceiptController@invoiceBill');

    Route::post('call-payment-status/{accident}', 'ReceiptController@callPaymentStatus');

    Route::get('document-release/{accident}', 'ReceiptController@documentRelease');

    Route::get('send-sms-again/{accident}', 'ReceiptController@sendSmsAgain');




});
//  receipt end


Route::get('map', function () {
    $activity_code = 0;
    switch (request()->type) {
        case 'camp':
            $activity_code = 1051;
            break;

        case 'campNew':
            $activity_code = 1115;
            break;

        case 'fastreact':
            $activity_code = 1114;
            break;

        case 'road_items':
            $activity_code = 1030;
            break;

        case 'pro':
            $activity_code = 1013;
            break;

        case 'rahdar':
            $activity_code = 1023;
            break;

        case 'safety_and_privacy':
            $activity_code = 1156;
            break;
    }

    if ($activity_code != 0) {
        auth()->user()->addActivityComplete($activity_code);
    }

    return view('version2.dashboard_pages.map');
})->name('v2.map');

Route::any('/safety_and_privacy/{any?}', fn() => abort(404, 'not found'))
    ->where('any', '.*');

Route::prefix('safety_and_privacy')->group(function () {

    Route::get('/sub_item_list', 'V2\Dashboard\SafetyAndPrivacyController@subItemList');


    Route::prefix('operator/cartable')->group(function () {
        Route::get('/', 'V2\Dashboard\SafetyAndPrivacyController@operatorCartable')->name('v2.safety_and_privacy.operator.cartable');
        Route::get('/show', 'V2\Dashboard\SafetyAndPrivacyController@operatorShow');
        Route::get('/unserialize/judiciary_document/{safety_and_privacy}', 'V2\Dashboard\SafetyAndPrivacyController@unserialize');
    });

    Route::prefix('operator')->group(function () {
        Route::get('/first_step', 'V2\Dashboard\SafetyAndPrivacyController@operatorFirstStepView')->name('v2.safety_and_privacy.operator.create');
        Route::post('/first_step', 'V2\Dashboard\SafetyAndPrivacyController@operatorFirstStepStore');
        Route::post('/second_step/{safety_and_privacy}', 'V2\Dashboard\SafetyAndPrivacyController@operatorSecondStepStore');
        Route::post('/third_step/{safety_and_privacy}', 'V2\Dashboard\SafetyAndPrivacyController@operatorThirdStepStore');
    });


    Route::prefix('report')->group(function () {

        Route::get('map', 'V2\Dashboard\SafetyAndPrivacyController@getAllDataToMap')->name('v2.safety_and_privacy.report.map');

        Route::get('', 'V2\Dashboard\SafetyAndPrivacyReportController@index')->name('v2.safety_and_privacy.report');
        Route::get('safety_and_privacy_data', 'V2\Dashboard\SafetyAndPrivacyReportController@safetyAndPrivacyData')->name('v2.safety_and_privacy.safety_and_privacy_data');
        Route::get('total_group_province_city', 'V2\Dashboard\SafetyAndPrivacyReportController@totalGroupProvinceCity')->name('v2.safety_and_privacy.total_group_province_city');

        Route::get('excel', 'V2\Dashboard\SafetyAndPrivacyReportController@safetyAndPrivacyExcel')->name('v2.safety_and_privacy.safety_and_privacy_excel');

    });


    Route::get('/{safety_and_privacy}', 'V2\Dashboard\SafetyAndPrivacyController@detail')->name('v2.safety_and_privacy.detail');
    Route::post('/delete/{safety_and_privacy}', 'V2\Dashboard\SafetyAndPrivacyController@delete');

});

/** TEST routes begin */
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

if (App::environment('local')) {
    Route::get('otp', function (Request $request) {
        return \App\Models\Otp::where('phone_number', $request->phone_number)->latest()->first();
    });
}
/** TEST routes end */


// Route::get('/road_item/report/map', 'index');
// Route::get('/road_homeprojects/report/map', 'index');