<?php

use App\Http\Controllers\ProfileController;
use App\Http\Controllers\BorrowController;
use App\Http\Controllers\CompanyController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\EarnController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\ProductsController;
use App\Http\Controllers\CryptoPriceController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

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

Route::get('/api/crypto/prices', CryptoPriceController::class);

Route::get('/products', [ProductsController::class, 'index'])->name('products');
Route::get('/borrow', [BorrowController::class, 'index'])->middleware('web')->name('borrow');
Route::get('/borrow/apply/{symbol}', [BorrowController::class, 'apply'])->middleware('auth')->name('borrow.apply');
Route::get('/company', [CompanyController::class, 'index'])->name('company');
Route::get('/earn', [EarnController::class, 'index'])->name('earn');

Route::post('/set-locale', function (Request $request) {
    $locale = (string) $request->input('locale', config('app.locale'));
    session(['locale' => $locale]);

    return redirect()->back();
})->name('set-locale');

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

Route::middleware('auth')->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

require __DIR__.'/auth.php';
