<?php

Route::redirect('/', '/login');
Route::get('/home', function () {
    if (session('status')) {
        return redirect()->route('admin.home')->with('status', session('status'));
    }

    return redirect()->route('admin.home');
});

Auth::routes(['register' => false]);

Route::group(['prefix' => 'admin', 'as' => 'admin.', 'namespace' => 'Admin', 'middleware' => ['auth', '2fa']], function () {
    Route::get('/', 'HomeController@index')->name('home');
    // Permissions
    Route::delete('permissions/destroy', 'PermissionsController@massDestroy')->name('permissions.massDestroy');
    Route::resource('permissions', 'PermissionsController');

    // Roles
    Route::delete('roles/destroy', 'RolesController@massDestroy')->name('roles.massDestroy');
    Route::resource('roles', 'RolesController');

    // Users
    Route::delete('users/destroy', 'UsersController@massDestroy')->name('users.massDestroy');
    Route::post('users/parse-csv-import', 'UsersController@parseCsvImport')->name('users.parseCsvImport');
    Route::post('users/process-csv-import', 'UsersController@processCsvImport')->name('users.processCsvImport');
    Route::resource('users', 'UsersController');

    // Audit Logs
    Route::resource('audit-logs', 'AuditLogsController', ['except' => ['create', 'store', 'edit', 'update', 'destroy']]);

    // Team
    Route::delete('teams/destroy', 'TeamController@massDestroy')->name('teams.massDestroy');
    Route::resource('teams', 'TeamController');

    // Faq Category
    Route::delete('faq-categories/destroy', 'FaqCategoryController@massDestroy')->name('faq-categories.massDestroy');
    Route::resource('faq-categories', 'FaqCategoryController');

    // Faq Question
    Route::delete('faq-questions/destroy', 'FaqQuestionController@massDestroy')->name('faq-questions.massDestroy');
    Route::resource('faq-questions', 'FaqQuestionController');

    // User Alerts
    Route::delete('user-alerts/destroy', 'UserAlertsController@massDestroy')->name('user-alerts.massDestroy');
    Route::get('user-alerts/read', 'UserAlertsController@read');
    Route::resource('user-alerts', 'UserAlertsController', ['except' => ['edit', 'update']]);

    // Fusion Categories
    Route::delete('fusion-categories/destroy', 'FusionCategoriesController@massDestroy')->name('fusion-categories.massDestroy');
    Route::post('fusion-categories/parse-csv-import', 'FusionCategoriesController@parseCsvImport')->name('fusion-categories.parseCsvImport');
    Route::post('fusion-categories/process-csv-import', 'FusionCategoriesController@processCsvImport')->name('fusion-categories.processCsvImport');
    Route::resource('fusion-categories', 'FusionCategoriesController');

    // Fusion Types
    Route::delete('fusion-types/destroy', 'FusionTypesController@massDestroy')->name('fusion-types.massDestroy');
    Route::post('fusion-types/parse-csv-import', 'FusionTypesController@parseCsvImport')->name('fusion-types.parseCsvImport');
    Route::post('fusion-types/process-csv-import', 'FusionTypesController@processCsvImport')->name('fusion-types.processCsvImport');
    Route::resource('fusion-types', 'FusionTypesController');

    // Products
    Route::delete('products/destroy', 'ProductsController@massDestroy')->name('products.massDestroy');
    Route::post('products/media', 'ProductsController@storeMedia')->name('products.storeMedia');
    Route::post('products/ckmedia', 'ProductsController@storeCKEditorImages')->name('products.storeCKEditorImages');
    Route::post('products/parse-csv-import', 'ProductsController@parseCsvImport')->name('products.parseCsvImport');
    Route::post('products/process-csv-import', 'ProductsController@processCsvImport')->name('products.processCsvImport');
    Route::resource('products', 'ProductsController');

    // Contact Company
    Route::delete('contact-companies/destroy', 'ContactCompanyController@massDestroy')->name('contact-companies.massDestroy');
    Route::post('contact-companies/parse-csv-import', 'ContactCompanyController@parseCsvImport')->name('contact-companies.parseCsvImport');
    Route::post('contact-companies/process-csv-import', 'ContactCompanyController@processCsvImport')->name('contact-companies.processCsvImport');
    Route::resource('contact-companies', 'ContactCompanyController');

    // Contact Contacts
    Route::delete('contact-contacts/destroy', 'ContactContactsController@massDestroy')->name('contact-contacts.massDestroy');
    Route::post('contact-contacts/parse-csv-import', 'ContactContactsController@parseCsvImport')->name('contact-contacts.parseCsvImport');
    Route::post('contact-contacts/process-csv-import', 'ContactContactsController@processCsvImport')->name('contact-contacts.processCsvImport');
    Route::get('contact-contacts/getLocationName', 'ContactContactsController@getLocationName')->name('contact-contacts.getLocationName');
    Route::resource('contact-contacts', 'ContactContactsController');

    // Asset
    Route::delete('assets/destroy', 'AssetController@massDestroy')->name('assets.massDestroy');
    Route::post('assets/media', 'AssetController@storeMedia')->name('assets.storeMedia');
    Route::post('assets/ckmedia', 'AssetController@storeCKEditorImages')->name('assets.storeCKEditorImages');
    Route::post('assets/parse-csv-import', 'AssetController@parseCsvImport')->name('assets.parseCsvImport');
    Route::post('assets/process-csv-import', 'AssetController@processCsvImport')->name('assets.processCsvImport');
    Route::get('assets/getAssetName', 'AssetController@getAssetName')->name('assets.getAssetName');
    Route::get('assets/createcommissionpdf/{Assetid}', 'AssetController@createcommissionpdf')->name('assets.createcommissionpdf');
    #Route::post('/asset/createsignedurl{user}', function (Request $request) {    })->name('unsubscribe')->middleware('signed');
    Route::get('/asset/createsignedurl/{user}', 'AssetController@createsignedurl')->name('signedurl');
    Route::resource('assets', 'AssetController');

    // Amc Contract
    Route::delete('amc-contracts/destroy', 'AmcContractController@massDestroy')->name('amc-contracts.massDestroy');
    Route::post('amc-contracts/media', 'AmcContractController@storeMedia')->name('amc-contracts.storeMedia');
    Route::post('amc-contracts/ckmedia', 'AmcContractController@storeCKEditorImages')->name('amc-contracts.storeCKEditorImages');
    Route::post('amc-contracts/parse-csv-import', 'AmcContractController@parseCsvImport')->name('amc-contracts.parseCsvImport');
    Route::post('amc-contracts/process-csv-import', 'AmcContractController@processCsvImport')->name('amc-contracts.processCsvImport');
    Route::resource('amc-contracts', 'AmcContractController');

    // Service Complaint
    Route::delete('service-complaints/destroy', 'ServiceComplaintController@massDestroy')->name('service-complaints.massDestroy');
    Route::post('service-complaints/parse-csv-import', 'ServiceComplaintController@parseCsvImport')->name('service-complaints.parseCsvImport');
    Route::post('service-complaints/process-csv-import', 'ServiceComplaintController@processCsvImport')->name('service-complaints.processCsvImport');
    Route::get('service-complaints/createcomplaintpdf/{Complaintid}', 'ServiceComplaintController@createcomplaintpdf')->name('service-complaints.createcomplaintpdf');
    Route::resource('service-complaints', 'ServiceComplaintController');

    // Checklist Report
    Route::delete('checklist-reports/destroy', 'ChecklistReportController@massDestroy')->name('checklist-reports.massDestroy');
    Route::post('checklist-reports/parse-csv-import', 'ChecklistReportController@parseCsvImport')->name('checklist-reports.parseCsvImport');
    Route::post('checklist-reports/process-csv-import', 'ChecklistReportController@processCsvImport')->name('checklist-reports.processCsvImport');
    Route::resource('checklist-reports', 'ChecklistReportController');

    // Commission Data
    Route::delete('commission-datas/destroy', 'CommissionDataController@massDestroy')->name('commission-datas.massDestroy');
    Route::post('commission-datas/parse-csv-import', 'CommissionDataController@parseCsvImport')->name('commission-datas.parseCsvImport');
    Route::post('commission-datas/process-csv-import', 'CommissionDataController@processCsvImport')->name('commission-datas.processCsvImport');
    Route::resource('commission-datas', 'CommissionDataController');

    // User Signature
    Route::delete('user-signatures/destroy', 'UserSignatureController@massDestroy')->name('user-signatures.massDestroy');
    Route::post('user-signatures/parse-csv-import', 'UserSignatureController@parseCsvImport')->name('user-signatures.parseCsvImport');
    Route::post('user-signatures/process-csv-import', 'UserSignatureController@processCsvImport')->name('user-signatures.processCsvImport');
    Route::resource('user-signatures', 'UserSignatureController');

    // All Reports
    Route::delete('all-reports/destroy', 'AllReportsController@massDestroy')->name('all-reports.massDestroy');
    Route::resource('all-reports', 'AllReportsController');

    Route::get('system-calendar', 'SystemCalendarController@index')->name('systemCalendar');
    Route::get('global-search', 'GlobalSearchController@search')->name('globalSearch');
    Route::get('messenger', 'MessengerController@index')->name('messenger.index');
    Route::get('messenger/create', 'MessengerController@createTopic')->name('messenger.createTopic');
    Route::post('messenger', 'MessengerController@storeTopic')->name('messenger.storeTopic');
    Route::get('messenger/inbox', 'MessengerController@showInbox')->name('messenger.showInbox');
    Route::get('messenger/outbox', 'MessengerController@showOutbox')->name('messenger.showOutbox');
    Route::get('messenger/{topic}', 'MessengerController@showMessages')->name('messenger.showMessages');
    Route::delete('messenger/{topic}', 'MessengerController@destroyTopic')->name('messenger.destroyTopic');
    Route::post('messenger/{topic}/reply', 'MessengerController@replyToTopic')->name('messenger.reply');
    Route::get('messenger/{topic}/reply', 'MessengerController@showReply')->name('messenger.showReply');
    Route::get('team-members', 'TeamMembersController@index')->name('team-members.index');
    Route::post('team-members', 'TeamMembersController@invite')->name('team-members.invite');
    #Route::post('creagia/sign-pad', LaravelSignPadController::class)->name('sign-pad::signature');
});
Route::group(['prefix' => 'profile', 'as' => 'profile.', 'namespace' => 'Auth', 'middleware' => ['auth', '2fa']], function () {
    // Change password
    if (file_exists(app_path('Http/Controllers/Auth/ChangePasswordController.php'))) {
        Route::get('password', 'ChangePasswordController@edit')->name('password.edit');
        Route::post('password', 'ChangePasswordController@update')->name('password.update');
        Route::post('profile', 'ChangePasswordController@updateProfile')->name('password.updateProfile');
        Route::post('profile/destroy', 'ChangePasswordController@destroy')->name('password.destroyProfile');
        Route::post('profile/two-factor', 'ChangePasswordController@toggleTwoFactor')->name('password.toggleTwoFactor');
    }
});
Route::group(['namespace' => 'Auth', 'middleware' => ['auth', '2fa']], function () {
    // Two Factor Authentication
    if (file_exists(app_path('Http/Controllers/Auth/TwoFactorController.php'))) {
        Route::get('two-factor', 'TwoFactorController@show')->name('twoFactor.show');
        Route::post('two-factor', 'TwoFactorController@check')->name('twoFactor.check');
        Route::get('two-factor/resend', 'TwoFactorController@resend')->name('twoFactor.resend');
    }
});
