<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Artisan;

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

Route::get('/storage-link', function () {
    try {
        Artisan::call('storage:link');
        return response()->json([
            'success' => true,
            'message' => 'Storage link created successfully.'
        ]);
    } catch (\Exception $e) {
        return response()->json([
            'success' => false,
            'message' => 'Failed to create storage link: ' . $e->getMessage()
        ]);
    }
});

Route::get('/hash-password', function () {
    $password = 'password123';

    // Hash using MD5
    $hashedPassword = md5($password);

    return "MD5 hash of '{$password}' is: {$hashedPassword}";
});

Route::get('/admin/optimize', function () {
    // Optional: restrict to admin users
    // if (!auth()->user()?->isAdmin) abort(403);

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

    return response()->json([
        'message' => '✅ Application cache cleared and optimized successfully!'
    ]);
});