using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using EventsAppQuest.Application.Services;
using EventsAppQuest.Core;
using EventsAppQuest.Domain.Enums;
using EventsAppQuest.Domain.Models;

namespace EventsAppQuest.Presentation
{
    /// <summary>
    /// Exibe resumo da selecao atual e do projeto em memoria: categoria, espaco, template,
    /// fornecedores selecionados, status e nome do projeto. Inclui botao Iniciar Projeto.
    /// </summary>
    public class SelectionSummaryView : MonoBehaviour
    {
        private const string LabelResumo = "Resumo da seleção";
        private const string LabelCategoria = "Categoria: ";
        private const string LabelEspaco = "Espaço: ";
        private const string LabelTemplate = "Template: ";
        private const string LabelFornecedoresSelecionados = "Fornecedores selecionados: ";
        private const string LabelProjeto = "Projeto: ";
        private const string LabelTema = "Tema: ";
        private const string LabelMood = "Mood: ";
        private const string LabelApresentacao = "Apresentação: ";
        private const string LabelNarrativa = "Narrativa: ";
        private const string LabelPronta = "Pronta para apresentação: ";
        private const string LabelVersoes = "Versões salvas: ";
        private const string LabelEvento = "Evento: ";
        private const string LabelCliente = "Cliente: ";
        private const string LabelConvidados = "Convidados: ";
        private const string LabelOrcamentoAlvo = "Orçamento alvo: ";
        private const string LabelAderencia = "Aderência: ";
        private const string LabelTransicoes = "Transições: ";
        private const string LabelFluidez = "Fluidez média: ";
        private const string LabelRoteiro = "Roteiro guiado: ";
        private const string LabelProntaGuiada = "Pronta p/ apresentação guiada: ";
        private const string LabelHotspots = "Hotspots visuais: ";
        private const string LabelHotspotPrincipal = "Principal: ";
        private const string LabelEstadosCena = "Estados da cena: ";
        private const string LabelEvolucaoVisual = "Evolução visual: ";
        private const string LabelComparacaoTemporal = "Comparação temporal: ";
        private const string LabelFasesComparacao = "Fases na comparação: ";
        private const string LabelRecomendacaoFinal = "Recomendação final: ";
        private const string LabelPropostaRecomendada = "Proposta recomendada: ";
        private const string LabelConfianca = "Confiança: ";
        private const string LabelResumoExecutivo = "Resumo executivo: ";
        private const string LabelProntidaoFechamento = "Prontidão p/ fechamento: ";
        private const string LabelProximaAcao = "Próxima ação: ";
        private const string LabelPlanoQuest = "Plano Quest/MR: ";
        private const string LabelModoApresentacao = "Modo apresentação: ";
        private const string LabelProntoMR = "Pronto p/ mapeamento MR: ";
        private const string Nenhum = "—";
        private const string NaoIniciado = "Não iniciado";

        private AppSession _session;
        private IProposalFitScoringService _scoringService;
        private IEventMomentTransitionService _transitionService;
        private Text _categoryText;
        private Text _spaceText;
        private Text _templateText;
        private Text _suppliersSelectedText;
        private Text _projectStatusText;
        private Text _eventNameText;
        private Text _clientNameText;
        private Text _guestsText;
        private Text _budgetTargetText;
        private Text _themeText;
        private Text _moodText;
        private Text _apresentacaoText;
        private Text _narrativaText;
        private Text _prontaText;
        private Text _versoesText;
        private Text _aderenciaText;
        private Text _transicoesText;
        private Text _fluidezText;
        private Text _roteiroText;
        private Text _prontaGuiadaText;
        private Text _hotspotsText;
        private Text _hotspotPrincipalText;
        private Text _estadosCenaText;
        private Text _evolucaoVisualText;
        private Text _comparacaoTemporalText;
        private Text _fasesComparacaoText;
        private Text _recomendacaoFinalText;
        private Text _propostaRecomendadaText;
        private Text _confiancaText;
        private Text _resumoExecutivoText;
        private Text _prontidaoFechamentoText;
        private Text _proximaAcaoText;
        private Text _planoQuestText;
        private Text _modoApresentacaoText;
        private Text _prontoMRText;

        private void Start()
        {
            _session = ServiceRegistry.Instance.Get<AppSession>();
            _scoringService = ServiceRegistry.Instance.Get<IProposalFitScoringService>();
            _transitionService = ServiceRegistry.Instance.Get<IEventMomentTransitionService>();
            if (_session != null)
                _session.OnSessionChanged += UpdateSummary;

            BuildUI();
            UpdateSummary();
        }

        private void OnDestroy()
        {
            if (_session != null)
                _session.OnSessionChanged -= UpdateSummary;
        }

        private void BuildUI()
        {
            var layout = gameObject.GetComponent<VerticalLayoutGroup>();
            if (layout == null)
            {
                layout = gameObject.AddComponent<VerticalLayoutGroup>();
                layout.spacing = 6;
                layout.padding = new RectOffset(10, 10, 10, 10);
                layout.childForceExpandHeight = false;
                layout.childForceExpandWidth = true;
            }

            var font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");

            CreateLabel(LabelResumo, 20, font, true);
            _categoryText = CreateLabel(LabelCategoria + Nenhum, 16, font, false);
            _spaceText = CreateLabel(LabelEspaco + Nenhum, 16, font, false);
            _templateText = CreateLabel(LabelTemplate + Nenhum, 16, font, false);
            _suppliersSelectedText = CreateLabel(LabelFornecedoresSelecionados + "0", 16, font, false);
            _projectStatusText = CreateLabel(LabelProjeto + NaoIniciado, 16, font, false);
            _eventNameText = CreateLabel(LabelEvento + Nenhum, 14, font, false);
            _clientNameText = CreateLabel(LabelCliente + Nenhum, 14, font, false);
            _guestsText = CreateLabel(LabelConvidados + Nenhum, 14, font, false);
            _budgetTargetText = CreateLabel(LabelOrcamentoAlvo + Nenhum, 14, font, false);
            _themeText = CreateLabel(LabelTema + Nenhum, 16, font, false);
            _moodText = CreateLabel(LabelMood + Nenhum, 16, font, false);
            _apresentacaoText = CreateLabel(LabelApresentacao + Nenhum, 16, font, false);
            _narrativaText = CreateLabel(LabelNarrativa + Nenhum, 16, font, false);
            _prontaText = CreateLabel(LabelPronta + Nenhum, 16, font, false);
            _versoesText = CreateLabel(LabelVersoes + "0", 16, font, false);
            _aderenciaText = CreateLabel(LabelAderencia + Nenhum, 14, font, false);
            _transicoesText = CreateLabel(LabelTransicoes + Nenhum, 14, font, false);
            _fluidezText = CreateLabel(LabelFluidez + Nenhum, 14, font, false);
            _roteiroText = CreateLabel(LabelRoteiro + Nenhum, 14, font, false);
            _prontaGuiadaText = CreateLabel(LabelProntaGuiada + Nenhum, 14, font, false);
            _hotspotsText = CreateLabel(LabelHotspots + Nenhum, 14, font, false);
            _hotspotPrincipalText = CreateLabel(LabelHotspotPrincipal + Nenhum, 14, font, false);
            _estadosCenaText = CreateLabel(LabelEstadosCena + Nenhum, 14, font, false);
            _evolucaoVisualText = CreateLabel(LabelEvolucaoVisual + Nenhum, 14, font, false);
            _comparacaoTemporalText = CreateLabel(LabelComparacaoTemporal + Nenhum, 14, font, false);
            _fasesComparacaoText = CreateLabel(LabelFasesComparacao + Nenhum, 14, font, false);
            _recomendacaoFinalText = CreateLabel(LabelRecomendacaoFinal + Nenhum, 14, font, false);
            _propostaRecomendadaText = CreateLabel(LabelPropostaRecomendada + Nenhum, 14, font, false);
            _confiancaText = CreateLabel(LabelConfianca + Nenhum, 14, font, false);
            _resumoExecutivoText = CreateLabel(LabelResumoExecutivo + Nenhum, 14, font, false);
            _prontidaoFechamentoText = CreateLabel(LabelProntidaoFechamento + Nenhum, 14, font, false);
            _proximaAcaoText = CreateLabel(LabelProximaAcao + Nenhum, 14, font, false);
            _planoQuestText = CreateLabel(LabelPlanoQuest + Nenhum, 14, font, false);
            _modoApresentacaoText = CreateLabel(LabelModoApresentacao + Nenhum, 14, font, false);
            _prontoMRText = CreateLabel(LabelProntoMR + Nenhum, 14, font, false);

            CreateIniciarProjetoButton(font);
        }

        private Text CreateLabel(string text, int fontSize, Font font, bool bold)
        {
            var go = new GameObject("Label");
            go.transform.SetParent(transform, false);
            var rt = go.AddComponent<RectTransform>();
            rt.sizeDelta = new Vector2(0, fontSize + 4);
            var t = go.AddComponent<Text>();
            t.text = text;
            t.font = font;
            t.fontSize = fontSize;
            t.fontStyle = bold ? FontStyle.Bold : FontStyle.Normal;
            return t;
        }

        private void CreateIniciarProjetoButton(Font font)
        {
            var go = new GameObject("IniciarProjetoButton");
            go.transform.SetParent(transform, false);
            var rt = go.AddComponent<RectTransform>();
            rt.sizeDelta = new Vector2(0, 36);
            var layoutElem = go.AddComponent<LayoutElement>();
            layoutElem.preferredHeight = 36;

            var image = go.AddComponent<Image>();
            image.color = new Color(0.2f, 0.5f, 0.2f, 1f);

            var button = go.AddComponent<Button>();
            button.targetGraphic = image;

            var labelGo = new GameObject("Text");
            labelGo.transform.SetParent(go.transform, false);
            var labelRt = labelGo.AddComponent<RectTransform>();
            labelRt.anchorMin = Vector2.zero;
            labelRt.anchorMax = Vector2.one;
            labelRt.offsetMin = Vector2.zero;
            labelRt.offsetMax = Vector2.zero;
            var labelText = labelGo.AddComponent<Text>();
            labelText.text = "Iniciar Projeto";
            labelText.font = font;
            labelText.fontSize = 18;
            labelText.alignment = TextAnchor.MiddleCenter;
            labelText.color = Color.white;

            button.onClick.AddListener(OnIniciarProjetoClicked);
        }

        private void OnIniciarProjetoClicked()
        {
            if (_session == null) return;

            var project = _session.StartProject("Meu evento");
            if (project != null)
                UpdateSummary();
        }

        private void UpdateSummary()
        {
            if (_session == null || _categoryText == null) return;

            _categoryText.text = LabelCategoria + (_session.SelectedCategory?.DisplayName ?? Nenhum);
            _spaceText.text = LabelEspaco + (_session.SelectedSpace?.Name ?? Nenhum);
            _templateText.text = LabelTemplate + (_session.SelectedTemplate?.Name ?? Nenhum);

            var selectedCount = _session.SelectedSupplierIds?.Count ?? 0;
            _suppliersSelectedText.text = LabelFornecedoresSelecionados + selectedCount;

            if (_session.CurrentProject != null)
            {
                var project = _session.CurrentProject;
                var statusStr = project.Status == EventProjectStatus.Draft ? "Rascunho" : "Pronta";
                _projectStatusText.text = LabelProjeto + statusStr + " — " + project.Name;
                var brief = project.ClientBrief;
                _eventNameText.text = LabelEvento + (brief != null && !string.IsNullOrEmpty(brief.EventName) ? brief.EventName : Nenhum);
                _clientNameText.text = LabelCliente + (brief != null && !string.IsNullOrEmpty(brief.ClientName) ? brief.ClientName : Nenhum);
                _guestsText.text = LabelConvidados + (brief != null && brief.GuestCount > 0 ? brief.GuestCount.ToString() : Nenhum);
                _budgetTargetText.text = LabelOrcamentoAlvo + (brief != null && brief.EstimatedBudgetTarget > 0 ? "R$ " + brief.EstimatedBudgetTarget.ToString("N0") : Nenhum);
                var themeName = ResolveThemeName(project.SelectedThemeId);
                var mood = ResolveMood(_session.CurrentProject.SelectedThemeId);
                _themeText.text = LabelTema + themeName;
                _moodText.text = LabelMood + mood;
                var stepCount = project.GeneratedPresentationSteps?.Count ?? 0;
                _apresentacaoText.text = LabelApresentacao + (stepCount > 0 ? stepCount + " etapa(s)" : Nenhum);
                _narrativaText.text = LabelNarrativa + (stepCount > 0 ? "Sim" : "Não");
                var review = project.LastProposalReviewSummary;
                _prontaText.text = LabelPronta + (review != null ? (review.IsReadyForPresentation ? "Sim" : "Não") : Nenhum);
                _versoesText.text = LabelVersoes + (_session.SavedSnapshots?.Count ?? 0);
                var activeProposal = project.GetActiveProposal();
                var fit = activeProposal?.FitScore;
                if (fit == null && _scoringService != null && activeProposal != null)
                {
                    fit = _scoringService.CalculateScore(project, activeProposal);
                    activeProposal.FitScore = fit;
                }
                _aderenciaText.text = LabelAderencia + (fit != null ? fit.OverallScore + "/100 — " + AderenciaStatus(fit.OverallScore) : Nenhum);
                var transList = activeProposal?.MomentTransitions ?? new List<EventMomentTransition>();
                if (transList.Count == 0 && _transitionService != null && activeProposal != null && (activeProposal.MomentPlans?.Count ?? 0) >= 2)
                {
                    var trans = _transitionService.GenerateTransitions(project, activeProposal);
                    if (trans != null && activeProposal != null) { activeProposal.MomentTransitions = new List<EventMomentTransition>(trans); transList = activeProposal.MomentTransitions; }
                }
                _transicoesText.text = LabelTransicoes + (transList.Count > 0 ? transList.Count.ToString() : Nenhum);
                if (transList.Count > 0)
                {
                    var sum = 0;
                    foreach (var t in transList) sum += t.SmoothnessScore;
                    _fluidezText.text = LabelFluidez + (sum / transList.Count);
                }
                else
                    _fluidezText.text = LabelFluidez + Nenhum;
                var guidedService = ServiceRegistry.Instance.Get<IProposalGuidedTourService>();
                var tourSteps = activeProposal?.GuidedTourSteps ?? new List<ProposalGuidedTourStep>();
                if (tourSteps.Count == 0 && guidedService != null && activeProposal != null)
                {
                    var generated = guidedService.GenerateGuidedTour(project, activeProposal);
                    if (generated != null) { activeProposal.GuidedTourSteps = new List<ProposalGuidedTourStep>(generated); tourSteps = activeProposal.GuidedTourSteps; }
                }
                _roteiroText.text = LabelRoteiro + (tourSteps.Count > 0 ? tourSteps.Count + " passos" : Nenhum);
                var reviewForGuided = project.LastProposalReviewSummary ?? activeProposal?.ReviewSummary;
                _prontaGuiadaText.text = LabelProntaGuiada + (reviewForGuided != null && reviewForGuided.ReadyForGuidedPresentation ? "Sim" : tourSteps.Count >= 3 ? "Completar revisão" : Nenhum);
                var hotspotService = ServiceRegistry.Instance.Get<IProposalVisualHotspotService>();
                var hotspotList = activeProposal?.VisualHotspots ?? new List<ProposalVisualHotspot>();
                if (hotspotList.Count == 0 && hotspotService != null && activeProposal != null)
                {
                    var generated = hotspotService.GenerateHotspots(project, activeProposal);
                    if (generated != null) { activeProposal.VisualHotspots = new List<ProposalVisualHotspot>(generated); hotspotList = activeProposal.VisualHotspots; }
                }
                _hotspotsText.text = LabelHotspots + (hotspotList.Count > 0 ? hotspotList.Count.ToString() : Nenhum) + (hotspotList.Any(h => h.IsPremiumUpsell) ? " (destaques premium)" : "");
                var primaryHotspot = hotspotList.OrderBy(h => h.HighlightPriority).FirstOrDefault();
                _hotspotPrincipalText.text = LabelHotspotPrincipal + (primaryHotspot != null ? (primaryHotspot.Title ?? "—") : Nenhum);
                var sceneStateService = ServiceRegistry.Instance.Get<IProposalSceneStateService>();
                var sceneStateList = activeProposal?.SceneStates ?? new List<ProposalSceneState>();
                if (sceneStateList.Count == 0 && sceneStateService != null && activeProposal != null)
                {
                    var generated = sceneStateService.GenerateSceneStates(project, activeProposal);
                    if (generated != null) { activeProposal.SceneStates = new List<ProposalSceneState>(generated); sceneStateList = activeProposal.SceneStates; }
                }
                _estadosCenaText.text = LabelEstadosCena + (sceneStateList.Count > 0 ? sceneStateList.Count.ToString() : Nenhum);
                var hasStructured = (project.LastProposalReviewSummary ?? activeProposal?.ReviewSummary)?.HasStructuredVisualEvolution ?? (sceneStateList.Count >= 2);
                _evolucaoVisualText.text = LabelEvolucaoVisual + (hasStructured ? "Sim" : "Não");
                var temporal = project.LastTemporalComparison;
                _comparacaoTemporalText.text = LabelComparacaoTemporal + (temporal != null ? "Sim" : "Não");
                _fasesComparacaoText.text = LabelFasesComparacao + (temporal?.PhaseComparisons != null && temporal.PhaseComparisons.Count > 0 ? temporal.PhaseComparisons.Count.ToString() : Nenhum);
                var recommendationService = ServiceRegistry.Instance.Get<IProposalRecommendationService>();
                var rec = project.LastRecommendationSummary;
                if (rec == null && recommendationService != null && project.Proposals != null && project.Proposals.Count > 0)
                {
                    rec = recommendationService.Recommend(project);
                    if (rec != null) project.LastRecommendationSummary = rec;
                }
                _recomendacaoFinalText.text = LabelRecomendacaoFinal + (rec != null ? "Sim" : "Não");
                if (rec != null)
                {
                    var recName = project.Proposals?.FirstOrDefault(p => p.Id == rec.RecommendedProposalId)?.Name ?? rec.RecommendedProposalId ?? Nenhum;
                    _propostaRecomendadaText.text = LabelPropostaRecomendada + recName;
                    _confiancaText.text = LabelConfianca + rec.RecommendationConfidenceScore + "/100";
                }
                else
                {
                    _propostaRecomendadaText.text = LabelPropostaRecomendada + Nenhum;
                    _confiancaText.text = LabelConfianca + Nenhum;
                }
                var decisionService = ServiceRegistry.Instance.Get<IProposalDecisionSummaryService>();
                var decision = project.LastDecisionSummary;
                if (decision == null && decisionService != null && project.Proposals != null && project.Proposals.Count > 0)
                {
                    decision = decisionService.Generate(project);
                    if (decision != null) project.LastDecisionSummary = decision;
                }
                _resumoExecutivoText.text = LabelResumoExecutivo + (decision != null ? "Sim" : "Não");
                if (decision != null)
                {
                    _prontidaoFechamentoText.text = LabelProntidaoFechamento + DecisionReadinessText(decision.DecisionReadinessLevel);
                    _proximaAcaoText.text = LabelProximaAcao + (string.IsNullOrEmpty(decision.SuggestedNextAction) ? Nenhum : decision.SuggestedNextAction);
                }
                else
                {
                    _prontidaoFechamentoText.text = LabelProntidaoFechamento + Nenhum;
                    _proximaAcaoText.text = LabelProximaAcao + Nenhum;
                }
                var activeProposal = project.GetActiveProposal();
                var mrPlan = activeProposal?.MRPresentationPlan;
                if (mrPlan == null && activeProposal != null)
                {
                    var mrService = ServiceRegistry.Instance.Get<IMRPresentationPlanningService>();
                    if (mrService != null)
                    {
                        mrPlan = mrService.GeneratePlan(project, activeProposal);
                        if (mrPlan != null) activeProposal.MRPresentationPlan = mrPlan;
                    }
                }
                _planoQuestText.text = LabelPlanoQuest + (mrPlan != null ? "Sim" : "Não");
                if (mrPlan != null)
                {
                    _modoApresentacaoText.text = LabelModoApresentacao + MRModeText(mrPlan.TargetExperienceMode);
                    _prontoMRText.text = LabelProntoMR + (mrPlan.ReadyForMRMapping ? "Sim" : "Não");
                }
                else
                {
                    _modoApresentacaoText.text = LabelModoApresentacao + Nenhum;
                    _prontoMRText.text = LabelProntoMR + Nenhum;
                }
            }
            else
            {
                _projectStatusText.text = LabelProjeto + NaoIniciado;
                _eventNameText.text = LabelEvento + Nenhum;
                _clientNameText.text = LabelCliente + Nenhum;
                _guestsText.text = LabelConvidados + Nenhum;
                _budgetTargetText.text = LabelOrcamentoAlvo + Nenhum;
                _themeText.text = LabelTema + Nenhum;
                _moodText.text = LabelMood + Nenhum;
                _apresentacaoText.text = LabelApresentacao + Nenhum;
                _narrativaText.text = LabelNarrativa + Nenhum;
                _prontaText.text = LabelPronta + Nenhum;
                _versoesText.text = LabelVersoes + "0";
                _aderenciaText.text = LabelAderencia + Nenhum;
                _transicoesText.text = LabelTransicoes + Nenhum;
                _fluidezText.text = LabelFluidez + Nenhum;
                _roteiroText.text = LabelRoteiro + Nenhum;
                _prontaGuiadaText.text = LabelProntaGuiada + Nenhum;
                _hotspotsText.text = LabelHotspots + Nenhum;
                _hotspotPrincipalText.text = LabelHotspotPrincipal + Nenhum;
                _estadosCenaText.text = LabelEstadosCena + Nenhum;
                _evolucaoVisualText.text = LabelEvolucaoVisual + Nenhum;
                _comparacaoTemporalText.text = LabelComparacaoTemporal + Nenhum;
                _fasesComparacaoText.text = LabelFasesComparacao + Nenhum;
                _recomendacaoFinalText.text = LabelRecomendacaoFinal + Nenhum;
                _propostaRecomendadaText.text = LabelPropostaRecomendada + Nenhum;
                _confiancaText.text = LabelConfianca + Nenhum;
                _resumoExecutivoText.text = LabelResumoExecutivo + Nenhum;
                _prontidaoFechamentoText.text = LabelProntidaoFechamento + Nenhum;
                _proximaAcaoText.text = LabelProximaAcao + Nenhum;
                _planoQuestText.text = LabelPlanoQuest + Nenhum;
                _modoApresentacaoText.text = LabelModoApresentacao + Nenhum;
                _prontoMRText.text = LabelProntoMR + Nenhum;
            }
        }

        private static string MRModeText(EventsAppQuest.Domain.Enums.MRPresentationTargetMode mode)
        {
            switch (mode)
            {
                case EventsAppQuest.Domain.Enums.MRPresentationTargetMode.GuidedSalesTour: return "Tour guiado";
                case EventsAppQuest.Domain.Enums.MRPresentationTargetMode.FreeExploration: return "Exploração livre";
                case EventsAppQuest.Domain.Enums.MRPresentationTargetMode.SideBySideComparison: return "Comparação";
                case EventsAppQuest.Domain.Enums.MRPresentationTargetMode.ExecutiveClosingMode: return "Fechamento executivo";
                default: return "—";
            }
        }

        private static string DecisionReadinessText(EventsAppQuest.Domain.Enums.ProposalDecisionReadinessLevel level)
        {
            switch (level)
            {
                case EventsAppQuest.Domain.Enums.ProposalDecisionReadinessLevel.NotReady: return "Não pronto";
                case EventsAppQuest.Domain.Enums.ProposalDecisionReadinessLevel.UnderReview: return "Em revisão";
                case EventsAppQuest.Domain.Enums.ProposalDecisionReadinessLevel.ReadyToPresent: return "Pronto p/ apresentar";
                case EventsAppQuest.Domain.Enums.ProposalDecisionReadinessLevel.ReadyToClose: return "Pronto p/ fechamento";
                default: return "—";
            }
        }

        private static string AderenciaStatus(int score)
        {
            if (score >= 75) return "Alta aderência";
            if (score >= 50) return "Aderência média";
            return "Baixa aderência";
        }

        private static string ResolveThemeName(string themeId)
        {
            if (string.IsNullOrEmpty(themeId)) return Nenhum;
            var service = ServiceRegistry.Instance.Get<IVisualThemeService>();
            var t = service?.GetById(themeId);
            return t?.Name ?? Nenhum;
        }

        private static string ResolveMood(string themeId)
        {
            if (string.IsNullOrEmpty(themeId)) return Nenhum;
            var service = ServiceRegistry.Instance.Get<IVisualThemeService>();
            var t = service?.GetById(themeId);
            return !string.IsNullOrEmpty(t?.Mood) ? t.Mood : Nenhum;
        }
    }
}
