<?php

use App\Http\Controllers\ProfileController;
use App\Http\Controllers\Public\MediaController;
use App\Http\Controllers\PushSubscriptionController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    if (Auth::check()) {
        return redirect()->to(Auth::user()->dashboardRoute());
    }
    return redirect()->route('login');
});

// Bridge: Breeze redirects to /dashboard tras login → reenviamos según rol.
Route::get('/dashboard', function () {
    return redirect()->to(Auth::user()->dashboardRoute());
})->middleware(['auth'])->name('dashboard');

Route::view('/empresa-suspendida', 'errors.company-suspended')
    ->middleware('auth')
    ->name('company.suspended');

Route::view('/offline', 'pwa.offline')->name('pwa.offline');

Route::get('/media/{path}', [MediaController::class, 'show'])
    ->where('path', '.*')
    ->name('public.media');

Route::get('/precios', [\App\Http\Controllers\Public\PricingController::class, 'index'])->name('pricing');
Route::post('/precios/checkout', [\App\Http\Controllers\Public\PricingController::class, 'checkout'])->name('pricing.checkout');

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');

    Route::post('/push-subscriptions', [PushSubscriptionController::class, 'store'])->name('push-subscriptions.store');
    Route::delete('/push-subscriptions', [PushSubscriptionController::class, 'destroy'])->name('push-subscriptions.destroy');
});
