<?php

namespace App\Support;

use App\Models\InvestmentSetting;
use App\Models\User;
use Illuminate\Http\Request;

final class MaintenanceMode
{
    public static function enabled(): bool
    {
        return (bool) InvestmentSetting::current()->maintenance_mode_enabled;
    }

    public static function allowsUser(?User $user): bool
    {
        return !is_null($user) && $user->is_admin;
    }

    /**
     * Rutas públicas de autenticación accesibles durante el mantenimiento.
     */
    public static function isAuthenticationRoute(Request $request): bool
    {
        if ($request->routeIs([
            'login',
            'login.store',
            'logout',
            'two-factor.login',
            'two-factor.login.store',
            'password.confirm',
            'password.confirm.store',
            'verification.notice',
            'verification.verify',
            'verification.send',
        ])) {
            return true;
        }

        return $request->is(
            'login',
            'logout',
            'two-factor-challenge',
            'user/confirm-password',
            'email/verify',
            'email/verify/*',
            'forgot-password',
            'reset-password',
            'reset-password/*',
        );
    }
}
