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

namespace EventsAppQuest.Web.Producer.Application
{
    /// <summary>
    /// Dados mock para o painel do produtor: pedidos com handoff, requisitos, notas e atualizações de status.
    /// </summary>
    public class MockProducerDataService : IMockProducerDataService
    {
        private readonly List<ProducerRequirementItem> _requirements = new List<ProducerRequirementItem>();
        private readonly List<ProducerExecutionNote> _notes = new List<ProducerExecutionNote>();
        private readonly List<ProducerStatusUpdate> _statusUpdates = new List<ProducerStatusUpdate>();

        public MockProducerDataService()
        {
            SeedMockData();
        }

        private void SeedMockData()
        {
            var now = DateTime.UtcNow;
            if (HandoffStore.GetOrders().Count > 0) return;

            var order1 = new ProducerOrder
            {
                OrderId = "ord-1",
                ProposalId = "prop-1",
                SessionId = "quest-session-001",
                OpportunityId = "opp-1",
                SourceLeadId = "lead-1",
                EventCategory = "Corporativo",
                ThemeLabel = "Premium Minimalista",
                SelectedCommercialPackageLabel = "Premium",
                RecommendedProposalId = "proposal-guid-1",
                SelectedProposalId = "proposal-guid-1",
                RequiredShowroomItems = new List<string> { "Mesa principal 20 lugares", "Iluminação cenográfica", "Buffet executivo" },
                KeyHotspots = new List<string> { "Entrada impactante", "Área de networking", "Palco principal" },
                KeyNotesFromSales = new List<string> { "Cliente confirmou CTA Fechar contrato na sessão Quest.", "Priorizar montagem do palco até 14h." },
                FollowUpPriority = FollowUpPriority.High,
                ProducerOrderStatus = ProducerOrderStatus.Accepted,
                CreatedAt = now.AddDays(-2),
                OrderSummary = "Evento corporativo 80 pax - Empresa PT. Proposta Premium. Sessão Quest realizada. Prioridade High.",
                AcceptanceStatus = ProducerAcceptanceStatus.Accepted,
                RequiresClarification = false,
                SalesHandoffNotes = "Próxima ação: Enviar detalhes do pacote premium.",
                GeneratedAt = now.AddDays(-2),
                AcceptedAt = now.AddDays(-1),
                LastUpdatedAt = now.AddDays(-1)
            };
            var order2 = new ProducerOrder
            {
                OrderId = "ord-2",
                ProposalId = "prop-3",
                SessionId = "quest-session-003",
                OpportunityId = "opp-3",
                SourceLeadId = "lead-3",
                EventCategory = "Casamento",
                ThemeLabel = "Rústico elegante",
                SelectedCommercialPackageLabel = "Luxury",
                RecommendedProposalId = "proposal-guid-3",
                SelectedProposalId = "proposal-guid-3",
                RequiredShowroomItems = new List<string> { "Arco floral", "Mesas redondas", "Iluminação ambiente", "Buffet sob medida" },
                KeyHotspots = new List<string> { "Cerimónia", "Mesa de doces", "Pista" },
                KeyNotesFromSales = new List<string> { "Alta intenção na sessão Quest. Próxima ação: enviar minuta.", "Tema aprovado pelo cliente." },
                FollowUpPriority = FollowUpPriority.Urgent,
                ProducerOrderStatus = ProducerOrderStatus.InPreparation,
                CreatedAt = now.AddDays(-5),
                OrderSummary = "Corporativo Ana Costa - Hotel Vista. Proposta Corporativo. Sessão Quest. Prioridade Urgent.",
                AcceptanceStatus = ProducerAcceptanceStatus.Accepted,
                RequiresClarification = false,
                SalesHandoffNotes = "Enviar minuta e agendar assinatura.",
                GeneratedAt = now.AddDays(-5),
                AcceptedAt = now.AddDays(-4),
                LastUpdatedAt = now.AddDays(-3)
            };
            var order3 = new ProducerOrder
            {
                OrderId = "ord-3",
                ProposalId = "prop-5",
                SessionId = null,
                OpportunityId = "opp-5",
                SourceLeadId = "lead-2",
                EventCategory = "Aniversário empresarial",
                ThemeLabel = "Moderno",
                SelectedCommercialPackageLabel = "Standard",
                RecommendedProposalId = null,
                SelectedProposalId = null,
                RequiredShowroomItems = new List<string> { "Cenário modular", "Sonorização" },
                KeyHotspots = new List<string>(),
                KeyNotesFromSales = new List<string> { "Proposta enviada; aguardar sessão Quest para confirmação." },
                FollowUpPriority = FollowUpPriority.Medium,
                ProducerOrderStatus = ProducerOrderStatus.New,
                CreatedAt = now.AddDays(-1),
                OrderSummary = "Aniversário empresarial Eventos & Cia. Proposta enviada. Aguardar sessão Quest.",
                AcceptanceStatus = ProducerAcceptanceStatus.PendingReview,
                RequiresClarification = false,
                SalesHandoffNotes = "Aguardar feedback; sugerir sessão Quest.",
                GeneratedAt = now.AddDays(-1),
                LastUpdatedAt = now.AddDays(-1)
            };
            HandoffStore.AddOrder(order1);
            HandoffStore.AddOrder(order2);
            HandoffStore.AddOrder(order3);

            _requirements.Add(new ProducerRequirementItem { Id = "req-1", OrderId = "ord-1", Type = ProducerRequirementType.Stage, Title = "Palco principal", Description = "Montagem até 14h", IsCompleted = false, DisplayOrder = 1 });
            _requirements.Add(new ProducerRequirementItem { Id = "req-2", OrderId = "ord-1", Type = ProducerRequirementType.Lighting, Title = "Iluminação cenográfica", Description = "Zona de networking e palco", IsCompleted = true, DisplayOrder = 2 });
            _requirements.Add(new ProducerRequirementItem { Id = "req-3", OrderId = "ord-1", Type = ProducerRequirementType.Buffet, Title = "Buffet executivo", Description = "Serviço 80 pax", IsCompleted = false, DisplayOrder = 3 });
            _requirements.Add(new ProducerRequirementItem { Id = "req-4", OrderId = "ord-2", Type = ProducerRequirementType.Decoration, Title = "Arco floral", Description = "Entrada cerimónia", IsCompleted = false, DisplayOrder = 1 });
            _requirements.Add(new ProducerRequirementItem { Id = "req-5", OrderId = "ord-2", Type = ProducerRequirementType.Furniture, Title = "Mesas redondas", Description = "12 mesas", IsCompleted = false, DisplayOrder = 2 });
            _requirements.Add(new ProducerRequirementItem { Id = "req-6", OrderId = "ord-2", Type = ProducerRequirementType.Logistics, Title = "Acesso e carga", Description = "Janela 08h-10h", IsCompleted = true, DisplayOrder = 3 });

            _notes.Add(new ProducerExecutionNote { Id = "n1", OrderId = "ord-1", Content = "Cliente pediu reforço de iluminação na área de networking.", AuthorLabel = "Comercial", CreatedAt = now.AddDays(-1) });
            _notes.Add(new ProducerExecutionNote { Id = "n2", OrderId = "ord-2", Content = "Florista confirmada para dia D.", AuthorLabel = "Produtor", CreatedAt = now.AddDays(-2) });

            _statusUpdates.Add(new ProducerStatusUpdate { Id = "su1", OrderId = "ord-1", PreviousStatus = ProducerOrderStatus.UnderReview, NewStatus = ProducerOrderStatus.Accepted, Note = "Aceite pelo produtor", CreatedAt = now.AddDays(-1) });
            _statusUpdates.Add(new ProducerStatusUpdate { Id = "su2", OrderId = "ord-2", PreviousStatus = ProducerOrderStatus.Accepted, NewStatus = ProducerOrderStatus.InPreparation, Note = "Montagem iniciada", CreatedAt = now.AddDays(-3) });
        }

        public IReadOnlyList<ProducerOrder> GetOrders() => HandoffStore.GetOrders();
        public void UpdateOrderAcceptance(string orderId, ProducerAcceptanceStatus status, string note = null, bool requiresClarification = false, string clarificationReason = null)
            => HandoffStore.UpdateAcceptance(orderId, status, note, requiresClarification, clarificationReason);

        public IReadOnlyList<ProducerRequirementItem> GetRequirements() => _requirements;
        public IReadOnlyList<ProducerExecutionNote> GetExecutionNotes() => _notes;
        public IReadOnlyList<ProducerStatusUpdate> GetStatusUpdates() => _statusUpdates;
    }
}
