<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\V1\ClientApiController;
// use App\Http\Controllers;

Route::get('/cache-clear', function () {
    Artisan::call('cache:clear');
    dd("Cache-Clear");
});

Route::get('/config-cache', function () {
    Artisan::call('config:cache');
    dd("Config-cache");
});

Route::get('/config-clear', function () {
    Artisan::call('config:clear');
    dd("Config-clear");
});

// Route::match(['GET', 'POST'], 'logout', [App\Http\Controllers\Admin\HomeController::class, 'logout'])->name('logout');

// HOME 
Route::group(
    ['namespace' => 'App\Http\Controllers'],
    function () {
        Route::get('/', 'HomeController@index')->name('/');
    }
);
//when not route is match 
// Route::fallback(function () {
//     return view('404');
// });

Route::get('preview', 'App\Http\Controllers\Api\V1\ClientApiController@preview');
Route::get('download', 'App\Http\Controllers\Api\V1\ClientApiController@download')->name('download');

Route::group(['middleware' => ['auth', 'checkRole:admin,manager']], function () {
    Route::group(
        ['namespace' => 'App\Http\Controllers', 'prefix' => 'admin', 'as' => 'admin.'],
        function () {
            Route::get('/dashboard', 'HomeController@dashboard')->name('dashboard');
            // PDF
            Route::get('/view-pdf', 'HomeController@viewPdf')->name('enrollDetail');
            // Profile 
            Route::get('/view-profile', 'HomeController@viewProfile')->name('profile');
            Route::post('/update-profile/{id}', 'HomeController@updateProfile')->name('updateProfile');
            // Site Settings 
            Route::get('/site-setting', 'HomeController@getSiteSetting')->name('sitesetting');
            Route::post('/change-setting/{id}', 'HomeController@updateSiteSetting')->name('changesetting');

            //Enrollment
            Route::get('/list-enrollment', 'EnrollmentController@viewEnrollment')->name('enrollmentList');
            Route::get('/approved-enrollment', 'EnrollmentController@approvedEnrollment')->name('enrollmentApproved');
            Route::get('/pending-enrollment', 'EnrollmentController@pendingEnrollment')->name('enrollmentPending');
            Route::post('/change-enrollment-status', 'EnrollmentController@changeStatus')->name('changeStatus');
            Route::get('/delete-enrollment/{id}', 'EnrollmentController@deleteEnrollment')->name('enrollmentDelete');
            Route::get('/history/{id}', 'EnrollmentController@getHistory')->name('enrollmentHistory');
            
            //Agent
            Route::get('/add-agent', 'HomeController@viewAgent')->name('agent');
            Route::post('/store-agent', 'HomeController@storeAgent')->name('storeagent'); 
            Route::get('/list-agent', 'HomeController@listAgent')->name('listagent');
            Route::get('/edit-agent/{id}', 'HomeController@editAgent')->name('editagent');
            Route::post('/update-agent/{id}', 'HomeController@updateAgent')->name('updateagent');
            Route::get('/delete-agent/{id}', 'HomeController@deleteAgent')->name('deleteagent');
        }
    );
});

//  Show routes to Admin only
Route::group(['middleware' => ['auth', 'can:admin-only']], function () {
    Route::group(
        ['namespace' => 'App\Http\Controllers', 'prefix' => 'admin', 'as' => 'admin.'],
        function () {
             //branch manager
             Route::get('/add-manager', 'HomeController@viewManager')->name('branchmanager');
             Route::post('/store-branch-manager', 'HomeController@storeManager')->name('storemanager');
             Route::get('/list-manager', 'HomeController@listManager')->name('listmanager');
             Route::get('/edit-manager/{id}', 'HomeController@editManager')->name('editmanager');
             Route::post('/update-branch-manager/{id}', 'HomeController@updateManager')->name('updatemanager');
             Route::get('/delete-manager/{id}', 'HomeController@deleteManager')->name('deletemanager');
             //Subscriber
             Route::get('/add-subscriber', 'HomeController@viewSubscriber')->name('subscriber');
             Route::post('/store-subscriber', 'HomeController@storeSubscriber')->name('storesubscriber'); 
             Route::get('/list-subscriber', 'HomeController@listSubscriber')->name('listsubscriber');
             Route::get('/edit-subscriber/{id}', 'HomeController@editSubscriber')->name('editsubscriber');
             Route::post('/update-subscriber/{id}', 'HomeController@updateSubscriber')->name('updatesubscriber');
             Route::get('/delete-subscriber/{id}', 'HomeController@deleteSubscriber')->name('deletesubscriber');

        }
    );
});

Auth::routes();

// Route::get('/dashboard', [HomeController::class, 'index'])->name('dashboard');
