<?php

use App\Http\Controllers\In_Charge\ChangePasswordController;
use App\Http\Controllers\In_Charge\ComplaintController;
use App\Http\Controllers\In_Charge\DashboardController;
use App\Http\Controllers\In_Charge\InactiveSubInChargeController;
use App\Http\Controllers\In_Charge\LiveRequestController;
use App\Http\Controllers\In_Charge\LoginController;
use App\Http\Controllers\In_Charge\ProfileController;
use App\Http\Controllers\In_Charge\ServiceController;
use App\Http\Controllers\In_Charge\StoryController;
use App\Http\Controllers\In_Charge\SubInChargeController;
use App\Http\Controllers\In_Charge\WorkingTimeController;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Artisan;


/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// Artisan
Route::get('artisan', function () {

    Artisan::call('config:clear');
    Artisan::call('config:cache');
    Artisan::call('cache:clear');
    Artisan::call('view:clear');
    Artisan::call('route:clear');

    return "<h1>All Config Cache Clear Successfully.</h1>";
});

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

    // Login-Logout
    Route::get('login', [LoginController::class, 'login'])->name('incharge.login');
    Route::post('login', [LoginController::class, 'save_login'])->name('incharge.save.login');
    Route::get('logout', [LoginController::class, 'logout'])->name('incharge.logout');

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

        Route::get('dashboard', [DashboardController::class, 'index'])->name('incharge.dashboard');
        // Dashboard
        Route::resource('inlive_request', LiveRequestController::class)->only(['index']);
        // Profile
        Route::resource('inprofile', ProfileController::class)->only(['index', 'update']);
        //  Change Passwored
        Route::resource('inchangepassword', ChangePasswordController::class)->only(['index', 'update']);
        // Working Time
        Route::resource('inworkingtime', WorkingTimeController::class)->only(['index', 'update']);
        // Service
        Route::resource('inservice', ServiceController::class)->only(['index', 'store', 'update', 'show']);
        Route::post('inservice/sortorder', [ServiceController::class, 'SortOrder'])->name('inservice.sortorder');
        // Story
        Route::resource('instory', StoryController::class)->only(['index', 'create', 'store', 'edit', 'update']);
        // Sub In-Charge
        Route::resource('insub_incharge', SubInChargeController::class)->only(['index', 'create', 'store', 'edit', 'update', 'show']);
        Route::post('insub_incharge/transfer', [SubInChargeController::class, 'transfer_sub_incharge'])->name('insub_incharge.transfer');
        // InActive Sub In-Charge
        Route::resource('ininactive_sub_incharge', InactiveSubInChargeController::class)->only(['index']);
        // complaint
        Route::resource('incomplaint', ComplaintController::class)->only(['index']);
        Route::get('incomplaint/details/{id}', [ComplaintController::class, 'complaintDetails'])->name('incomplaint.details');
        Route::post('incomplaint/details/update', [ComplaintController::class, 'complaintDetailsUpdate'])->name('incomplaint.details.update');
        Route::post('incomplaint/image/save', [ComplaintController::class, 'complaint_after_image'])->name('incomplaint.image.save');

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

            // Category
            Route::resource('inservice', ServiceController::class)->only(['destroy']);
            // Story
            Route::resource('instory', StoryController::class)->only(['show']);
            // Sub In-Charge
            Route::resource('insub_incharge', SubInChargeController::class)->only(['destroy']);
            // complaint
            Route::resource('incomplaint', ComplaintController::class)->only(['destroy']);
        });
    });
});
