<?php

namespace App\Enums\Hotel;

/**
 * Define la configuración de riesgo asociada a cada tipo de comportamiento.
 *
 * Este enum centraliza:
 * - Score de riesgo (0 - 100)
 * - Nivel de riesgo (none, low, medium, high, critical)
 *
 * Permite modificar reglas de riesgo sin afectar el enum principal BehaviorReport.
 */
enum BehaviorRisk: string
{
    case NONE                 = 'none';
    case MINOR_INCIDENT       = 'minor_incident';
    case ADMINISTRATIVE_ISSUE = 'administrative_issue';
    case POLICY_VIOLATION     = 'policy_violation';
    case PAYMENT_RISK         = 'payment_risk';
    case OPERATIONAL_RISK     = 'operational_risk';
    case NOT_RECOMMENDED      = 'not_recommended';
    case RESTRICTED           = 'restricted';
    case BLACKLISTED          = 'blacklisted';

    /**
     * Obtiene el puntaje de riesgo asociado.
     *
     * @return int Valor entre 0 y 100.
     */
    public function score(): int
    {
        return match ($this) {
            self::NONE                 => 0,
            self::MINOR_INCIDENT       => 10,
            self::ADMINISTRATIVE_ISSUE => 25,
            self::POLICY_VIOLATION     => 40,
            self::PAYMENT_RISK         => 55,
            self::OPERATIONAL_RISK     => 65,
            self::NOT_RECOMMENDED      => 75,
            self::RESTRICTED           => 85,
            self::BLACKLISTED          => 100,
        };
    }

    /**
     * Obtiene el nivel de riesgo basado en el score.
     *
     * @return string none | low | medium | high | critical
     */
    public function level(): string
    {
        return match (true) {
            $this->score() === 0 => 'none',
            $this->score() <= 30 => 'low',
            $this->score() <= 60 => 'medium',
            $this->score() <= 85 => 'high',
            default              => 'critical',
        };
    }

    /**
     * Obtiene el color respectivo del nivel de riesgo basado en el score.
     *
     * @return string Hex Color
     */
    public function color(): string
    {
        return match (true) {
            $this->score() === 0 => '#6B7280', // Gris neutro
            $this->score() <= 30 => '#16A34A', // Verde (low)
            $this->score() <= 60 => '#D97706', // Naranja (medium)
            $this->score() <= 85 => '#DC3545', // Rojo (high)
            default              => '#7F1D1D', // Rojo oscuro (critical)
        };
    }

    /**
     * Obtiene la etiqueta traducida del nivel de riesgo.
     *
     * @return string
     */
    public function levelLabel(): string
    {
        $lang = __('enums')['common']['risk_level'];

        return $lang[$this->level()] ?? $this->level();
    }
}
