<?php
use Illuminate\Support\Facades\Route;
use Modules\Category\Controllers\Employee\CategoryController;
use Modules\Company\Controllers\Employee\CompanyController;
use Modules\ContactList\Controllers\Employee\ContactListController;
use Modules\Country\Controllers\Employee\CountryController;
use Modules\DailyLog\Controllers\Employee\DailyLogController;
use Modules\Deal\Controllers\Employee\DealController;
use Modules\DealStatus\Controllers\Employee\DealStatusController;
use Modules\Product\Controllers\Employee\ProductController;
use Modules\Region\Controllers\Employee\RegionController;
use Modules\Sector\Controllers\Employee\SectorController;
use Modules\Target\Controllers\Employee\TargetController;
use Modules\User\Controllers\Admin\UserController;
use Modules\User\Controllers\Employee\LoginController;
use Modules\User\Controllers\Employee\DashboardController;
use Modules\User\Controllers\Employee\EmployeeController;
use Modules\User\Controllers\Employee\ProfileController;

    Route::group([ 'prefix'=> 'employee' ], function () {
            Route::get('/login', [LoginController::class,'index']);
            Route::post('/login',  [LoginController::class,'authenticate'])->name('employee_login');
            Route::group([ 'middleware' => ['employee_auth']], function () {
                Route::get('/', [DashboardController::class,'index'])->name('employee_dashboard')->middleware('employee_config');
                Route::get('/logout', [LoginController::class,'logout'])->name('employee_logout');
                Route::get('/dashboard/stats', [DashboardController::class,'stats'])->name('employee.home.stats');
                Route::get('/dashboard/modules', [DashboardController::class,'modules'])->name('employee_dashboard.modules');
            });


        Route::group([ 'middleware' => ['employee_auth','employee_config']], function () {

            Route::get('/dashboard/modules', [DashboardController::class,'modules'])->name('employee.modules');

            Route::get('fetch/company',[DealController::class,'fetchCompany'])->name('employee.fetch.company');
            Route::get('fetch/company/sector',[ContactListController::class,'fetchCompanySector'])->name('employee.fetch.company.sector');
            Route::get('fetch/sector',[DealController::class,'fetchSector'])->name('employee.fetch.sector');
            Route::get('add/item',[DealController::class,'addItem'])->name('employee.add.item');
            Route::get('add/phone',[ContactListController::class,'addPhone'])->name('employee.add.phone');
            Route::get('fetch/target',[TargetController::class,'fetchTarget'])->name('employee.fetch.target');
            Route::get('fetch/target/show',[TargetController::class,'fetchTargetShow'])->name('employee.fetch.target.show');
            Route::get('fetch/budget',[ContactListController::class,'fetchBudget'])->name('employee.fetch.budget');
            Route::get('fetch/contact/list',[DailyLogController::class,'fetchContactList'])->name('employee.fetch.contact_list');
            Route::get('fetch/column/toggle',[UserController::class,'fetchColumnToggle'])->name('employee.fetch.route_column_toggle');
            Route::get('fetch/managers',[EmployeeController::class,'fetchManagers'])->name('employee.fetch.managers');
            Route::get('fetch/regions',[CompanyController::class,'fetchRegions'])->name('employee.fetch.regions');
            Route::get('fetch/sectors',[DealController::class,'fetchEmployee'])->name('admin.fetch.employee');


            Route::resource('/profile', ProfileController::class)->names('employee.profile')->only(['index','store']);

            Route::group([ 'middleware' => ['checkRoleEmployee']], function () {

                // Employee ROUTES
                Route::put('/employees/restore/{id}', [EmployeeController::class,'restore'])->name('employee.employees.restore');
                Route::put('/employees/restore', [EmployeeController::class,'restoreAll'])->name('employee.employees.restoreAll');
                Route::delete('/employees', [EmployeeController::class,'destroyAll'])->name('employee.employees.destroyAll');
                Route::get('/employees/grid', [EmployeeController::class,'grid'])->name('employee.employees.grid');
                Route::resource('/employees', EmployeeController::class)->names('employee.employees');
                Route::get('/employees/target/{id}', [EmployeeController::class,'target'])->name('employee.employees.target');

                // ContactList ROUTES
                Route::put('/contact_lists/restore/{id}', [ContactListController::class,'restore'])->name('employee.contact_lists.restore');
                Route::put('/contact_lists/restore', [ContactListController::class,'restoreAll'])->name('employee.contact_lists.restoreAll');
                Route::delete('/contact_lists', [ContactListController::class,'destroyAll'])->name('employee.contact_lists.destroyAll');
                Route::get('/contact_lists/grid', [ContactListController::class,'grid'])->name('employee.contact_lists.grid');
                Route::resource('/contact_lists', ContactListController::class)->names('employee.contact_lists');

                // Company ROUTES
                Route::put('/companies/restore/{id}', [CompanyController::class,'restore'])->name('employee.companies.restore');
                Route::put('/companies/restore', [CompanyController::class,'restoreAll'])->name('employee.companies.restoreAll');
                Route::delete('/companies', [CompanyController::class,'destroyAll'])->name('employee.companies.destroyAll');
                Route::get('/companies/grid', [CompanyController::class,'grid'])->name('employee.companies.grid');
                Route::resource('/companies', CompanyController::class)->names('employee.companies');

                // DealStatus ROUTES
                Route::put('/deal_statuses/restore/{id}', [DealStatusController::class,'restore'])->name('employee.deal_statuses.restore');
                Route::put('/deal_statuses/restore', [DealStatusController::class,'restoreAll'])->name('employee.deal_statuses.restoreAll');
                Route::delete('/deal_statuses', [DealStatusController::class,'destroyAll'])->name('employee.deal_statuses.destroyAll');
                Route::get('/deal_statuses/grid', [DealStatusController::class,'grid'])->name('employee.deal_statuses.grid');
                Route::resource('/deal_statuses', DealStatusController::class)->names('employee.deal_statuses');

                // Sector ROUTES
                Route::put('/sectors/restore/{id}', [SectorController::class,'restore'])->name('employee.sectors.restore');
                Route::put('/sectors/restore', [SectorController::class,'restoreAll'])->name('employee.sectors.restoreAll');
                Route::delete('/sectors', [SectorController::class,'destroyAll'])->name('employee.sectors.destroyAll');
                Route::get('/sectors/grid', [SectorController::class,'grid'])->name('employee.sectors.grid');
                Route::resource('/sectors', SectorController::class)->names('employee.sectors');

                // Deal ROUTES
                Route::put('/deals/restore/{id}', [DealController::class,'restore'])->name('employee.deals.restore');
                Route::put('/deals/restore', [DealController::class,'restoreAll'])->name('employee.deals.restoreAll');
                Route::delete('/deals', [DealController::class,'destroyAll'])->name('employee.deals.destroyAll');
                Route::get('/deals/grid', [DealController::class,'grid'])->name('employee.deals.grid');
                Route::resource('/deals', DealController::class)->names('employee.deals');

                // Country ROUTES
                Route::put('/countries/restore/{id}', [CountryController::class,'restore'])->name('employee.countries.restore');
                Route::put('/countries/restore', [CountryController::class,'restoreAll'])->name('employee.countries.restoreAll');
                Route::delete('/countries', [CountryController::class,'destroyAll'])->name('employee.countries.destroyAll');
                Route::get('/countries/grid', [CountryController::class,'grid'])->name('employee.countries.grid');
                Route::resource('/countries', CountryController::class)->names('employee.countries');

                // Region ROUTES
                Route::put('/regions/restore/{id}', [RegionController::class,'restore'])->name('employee.regions.restore');
                Route::put('/regions/restore', [RegionController::class,'restoreAll'])->name('employee.regions.restoreAll');
                Route::delete('/regions', [RegionController::class,'destroyAll'])->name('employee.regions.destroyAll');
                Route::get('/regions/grid', [RegionController::class,'grid'])->name('employee.regions.grid');
                Route::get('/regions/lock/{id}', [RegionController::class,'lock'])->name('employee.regions.lock');
                Route::resource('/regions', RegionController::class)->names('employee.regions');

                // Product ROUTES
                Route::put('/products/restore/{id}', [ProductController::class,'restore'])->name('employee.products.restore');
                Route::put('/products/restore', [ProductController::class,'restoreAll'])->name('employee.products.restoreAll');
                Route::delete('/products', [ProductController::class,'destroyAll'])->name('employee.products.destroyAll');
                Route::get('/products/grid', [ProductController::class,'grid'])->name('employee.products.grid');
                Route::resource('/products', ProductController::class)->names('employee.products');

                // Target ROUTES
                Route::put('/targets/restore/{id}', [TargetController::class,'restore'])->name('employee.targets.restore');
                Route::put('/targets/restore', [TargetController::class,'restoreAll'])->name('employee.targets.restoreAll');
                Route::delete('/targets', [TargetController::class,'destroyAll'])->name('employee.targets.destroyAll');
                Route::get('/targets/grid', [TargetController::class,'grid'])->name('employee.targets.grid');
                Route::get('/targets/showTarget', [TargetController::class,'show'])->name('employee.targets.showTarget');
                Route::get('/targets/editTarget',[TargetController::class,'editTarget'])->name('employee.targets.editTarget');
                Route::post('/targets/editTarget',[TargetController::class,'editTarget'])->name('employee.targets.editTarget');
                Route::resource('/targets', TargetController::class)->names('employee.targets')->except(['show','edit','update']);

                // Category ROUTES
                Route::put('/categories/restore/{id}', [CategoryController::class,'restore'])->name('employee.categories.restore');
                Route::put('/categories/restore', [CategoryController::class,'restoreAll'])->name('employee.categories.restoreAll');
                Route::delete('/categories', [CategoryController::class,'destroyAll'])->name('employee.categories.destroyAll');
                Route::get('/categories/grid', [CategoryController::class,'grid'])->name('employee.categories.grid');
                Route::resource('/categories', CategoryController::class)->names('employee.categories');

                // DailyLog ROUTES
                Route::put('/daily_logs/restore/{id}', [DailyLogController::class,'restore'])->name('employee.daily_logs.restore');
                Route::put('/daily_logs/restore', [DailyLogController::class,'restoreAll'])->name('employee.daily_logs.restoreAll');
                Route::delete('/daily_logs', [DailyLogController::class,'destroyAll'])->name('employee.daily_logs.destroyAll');
                Route::get('/daily_logs/grid', [DailyLogController::class,'grid'])->name('employee.daily_logs.grid');
                Route::resource('/daily_logs', DailyLogController::class)->names('employee.daily_logs');


            });  // End Role Routes

            // Route::post('/languages/{id}', 'LanguageController@update')->name('languages');

        }); // End Authenticated Web routes
    }); // End Web Routes
