<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Artisan;
use App\Http\Controllers\UserController;
use App\Http\Controllers\CallLogController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\DashboardController;

/*
|--------------------------------------------------------------------------
| 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!
|
*/

Route::get('/', function () {
    return view('welcome');
});


Route::get('/', function () {
    return redirect()->route('login');
});

Route::get('/create_storage_link', function () {

    // if (is_dir(public_path('storage'))) {
    //     rmdir(public_path('storage'));
    // }
    Artisan::call('storage:link');
});

Route::get('/clear_cache', function () {
    Artisan::call('config:clear');
    Artisan::call('view:clear');
    Artisan::call('route:clear');
    Artisan::call('cache:clear');
});


Route::get('/migrate', function () {
    if (config('app.env') == 'local') {
        Artisan::call('migrate');
    }
});


Route::middleware(['auth'])->prefix('')->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'dashboard'])->name('dashboard');
    Route::get('/call_log/delete_all', [CallLogController::class, 'delete_all'])->name('call_log.delete_all');
    Route::get('/profile/index', [ProfileController::class, 'index'])->name('profile.index');
    Route::post('/profile/update', [ProfileController::class, 'update'])->name('profile.update');
    Route::post('/profile/update_admin_password', [ProfileController::class, 'update_admin_password'])
        ->name('profile.update_admin_password');

    Route::resource('user', UserController::class);
});
