using System;
using System.Collections.Generic;
using EventsAppQuest.Web.Core;
using EventsAppQuest.Web.Domain;

namespace EventsAppQuest.Web.Application
{
    /// <summary>
    /// Implementação mock dos indicadores CRM (lógica simples, sem complexidade excessiva).
    /// </summary>
    public class CRMIndicatorsService : ICRMIndicatorsService
    {
        public IReadOnlyList<string> GetIndicatorsForOpportunity(SalesOpportunity opportunity, SessionRecord session, ProposalRecord proposal)
        {
            var list = new List<string>();

            if (opportunity.Stage == OpportunityStage.ReadyToClose)
                list.Add("Pronta para fechamento");

            if (session != null && session.FinalDecisionState == WebSessionDecisionState.ReadyToClose)
                list.Add("Alta intenção comercial");

            if (session != null && (session.FinalDecisionState == WebSessionDecisionState.Interested || session.FinalDecisionState == WebSessionDecisionState.NeedsFollowUp))
                list.Add("Precisa follow-up");
            if (session != null && session.FinalDecisionState == WebSessionDecisionState.ExplorationOnly)
                list.Add("Sessão pouco conclusiva");
            if (session != null && !string.IsNullOrEmpty(session.QualityLabel) && (session.QualityLabel.IndexOf("Low", StringComparison.OrdinalIgnoreCase) >= 0 || session.QualityLabel.IndexOf("Baixa", StringComparison.OrdinalIgnoreCase) >= 0))
                list.Add("Precisa revisar proposta");
            if (session != null && session.SuggestedNextAction != null && session.SuggestedNextAction.Length > 0 &&
                (session.FinalDecisionState == WebSessionDecisionState.Interested || session.FinalDecisionState == WebSessionDecisionState.NeedsFollowUp))
                list.Add("Sessão pronta para follow-up");

            if (opportunity.CommercialPriority == CommercialPriority.High || opportunity.CommercialPriority == CommercialPriority.Critical)
                list.Add("Prioridade alta");

            if (proposal != null && proposal.Status == ProposalRecordStatus.Sent && session == null)
                list.Add("Aguardar sessão Quest");

            return list;
        }

        public IReadOnlyList<string> GetIndicatorsForProposal(ProposalRecord proposal, SalesOpportunity opportunity)
        {
            var list = new List<string>();

            if (proposal.Status == ProposalRecordStatus.Sent)
            {
                if (opportunity != null && opportunity.Stage == OpportunityStage.FollowUp)
                    list.Add("Proposta em risco");
                else if (proposal.ViewedAt == null)
                    list.Add("Não visualizada");
            }

            if (proposal.Status == ProposalRecordStatus.Expired)
                list.Add("Expirada");

            return list;
        }
    }
}
