<?php

namespace App\Support;

/**
 * Picks a sensible emoji for common personal-finance labels when there is no brand match
 * and no explicit icon was provided (avoids meaningless single-letter monograms).
 */
final class LabelIntentIcon
{
    /** @var list<array{terms: list<string>, emoji: string}> */
    private const RULES = [
        [['pet insurance', 'dog insurance', 'cat insurance', 'seguro de animais', 'seguro animal'], '🐾'],
        [['car insurance', 'auto insurance', 'motor insurance', 'vehicle insurance', 'seguro automovel', 'seguro auto'], '🚗'],
        [['home insurance', 'house insurance', 'renters insurance', 'contents insurance', 'seguro habitacao', 'seguro casa', 'multirisco habitacao'], '🏠'],
        [['life insurance', 'seguro de vida', 'seguro vida'], '🛡️'],
        [['health insurance', 'medical insurance', 'seguro de saude', 'seguro saude', 'mutuelle'], '🏥'],
        [['rent', 'mortgage', 'lease', 'landlord', 'housing', 'aluguel', 'renda habitacional', 'condo fee', 'hoa fee', 'condominio', 'hipoteca'], '🏠'],
        [['pet', 'pets', 'veterinary', 'vet bill', 'dog food', 'cat food', 'cao', 'gato', 'racao'], '🐾'],
        [['insurance', 'seguro'], '🛡️'],
        [['electric', 'electricity', 'water bill', 'gas bill', 'utilities', 'energia', 'eletricidade', 'água', 'e-distribuzione', 'edf'], '⚡'],
        [['gym', 'fitness', 'workout', 'peloton', 'ginasio', 'gymnasium'], '💪'],
        [['salary', 'payroll', 'paycheque', 'paycheck', 'wage', 'stipend', 'ordenado', 'vencimento', 'subsidio'], '💼'],
        [['doctor', 'hospital', 'pharmacy', 'clinic', 'dentist', 'medico', 'farmacia', 'clinica'], '🏥'],
        [['birthday', 'anniversary gift', 'presente', 'prenda'], '🎁'],
        [['savings', 'emergency fund', 'poupanca', 'tesouro'], '🐖'],
        [['subscription', 'membership', 'recurring', 'mensalidade', 'assinatura'], '🔁'],
        [['vpn', 'cloud storage', 'hosting', 'dominio'], '🔐'],
        [['phone', 'mobile', 'internet', 'broadband', 'fiber', 'telemovel', 'telefone', 'vodafone', 'meo'], '📱'],
        [['travel', 'flight', 'hotel', 'viagem', 'voo'], '✈️'],
        [['education', 'course', 'tuition', 'school', 'universidade', 'escola'], '🎓'],
        [['debt', 'loan', 'credit card', 'financiamento', 'empréstimo'], '💳'],
        [['savings goal', 'financial goal', 'objetivo', 'metas'], '🎯'],
    ];

    public static function emoji(?string $label): ?string
    {
        if ($label === null || trim($label) === '') {
            return null;
        }
        foreach (self::RULES as [$terms, $emoji]) {
            if (FinancialKeywordMatch::containsAny($label, $terms)) {
                return $emoji;
            }
        }

        return null;
    }
}
