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

namespace EventsAppQuest.Infrastructure.Services
{
    /// <summary>
    /// Implementação mock de pacotes comerciais por template (casamento, aniversário, business).
    /// </summary>
    public class MockCommercialPackageService : ICommercialPackageService
    {
        private readonly List<ProposalCommercialPackage> _packages = new List<ProposalCommercialPackage>();

        public MockCommercialPackageService()
        {
            // Casamento (tpl-2): Essential, Premium, Luxury
            _packages.Add(new ProposalCommercialPackage
            {
                Id = "pkg-wedding-essential",
                Name = "Casamento Essential",
                Tier = CommercialPackageTier.Essential,
                Description = "Cerimônia essencial: arco e palco.",
                EventTemplateId = "tpl-2",
                IncludedShowroomItemIds = new List<string> { "shr-5", "shr-7" },
                SuggestedThemeIds = new List<string> { "theme-wedding-elegant" },
                TargetBudgetRangeMin = 3000f,
                TargetBudgetRangeMax = 6000f,
                UpsellNotes = "Inclua mesa de doces e iluminação (Premium) para recepção completa.",
                DownsellNotes = "Pacote enxuto; ideal para cerimônia intimista.",
                DisplayOrder = 1
            });
            _packages.Add(new ProposalCommercialPackage
            {
                Id = "pkg-wedding-premium",
                Name = "Casamento Premium",
                Tier = CommercialPackageTier.Premium,
                Description = "Cerimônia e recepção: arco, palco, mesa de doces e iluminação.",
                EventTemplateId = "tpl-2",
                IncludedShowroomItemIds = new List<string> { "shr-5", "shr-7", "shr-6", "shr-8" },
                SuggestedThemeIds = new List<string> { "theme-wedding-elegant", "theme-wedding-clean" },
                TargetBudgetRangeMin = 8000f,
                TargetBudgetRangeMax = 18000f,
                UpsellNotes = "Considere itens extras ou upgrade de iluminação (Luxury).",
                DownsellNotes = "Para orçamento mais enxuto, veja Essential.",
                DisplayOrder = 2
            });
            _packages.Add(new ProposalCommercialPackage
            {
                Id = "pkg-wedding-luxury",
                Name = "Casamento Luxury",
                Tier = CommercialPackageTier.Luxury,
                Description = "Pacote completo com todos os itens de destaque.",
                EventTemplateId = "tpl-2",
                IncludedShowroomItemIds = new List<string> { "shr-5", "shr-7", "shr-6", "shr-8" },
                SuggestedThemeIds = new List<string> { "theme-wedding-elegant", "theme-wedding-clean" },
                TargetBudgetRangeMin = 18000f,
                TargetBudgetRangeMax = 50000f,
                UpsellNotes = "Pacote top de linha; personalize com itens adicionais.",
                DownsellNotes = "Para ajuste de orçamento, veja Premium ou Essential.",
                DisplayOrder = 3
            });

            // Aniversário (tpl-1): Standard, Premium
            _packages.Add(new ProposalCommercialPackage
            {
                Id = "pkg-birthday-standard",
                Name = "Aniversário Standard",
                Tier = CommercialPackageTier.Standard,
                Description = "Mesa do bolo e decoração temática.",
                EventTemplateId = "tpl-1",
                IncludedShowroomItemIds = new List<string> { "shr-1", "shr-2" },
                SuggestedThemeIds = new List<string> { "theme-birthday-gold" },
                TargetBudgetRangeMin = 1500f,
                TargetBudgetRangeMax = 3500f,
                UpsellNotes = "Inclua buffet e iluminação (Premium) para festa completa.",
                DownsellNotes = "Pacote ideal para eventos menores.",
                DisplayOrder = 4
            });
            _packages.Add(new ProposalCommercialPackage
            {
                Id = "pkg-birthday-premium",
                Name = "Aniversário Premium",
                Tier = CommercialPackageTier.Premium,
                Description = "Mesa do bolo, decoração, buffet e iluminação.",
                EventTemplateId = "tpl-1",
                IncludedShowroomItemIds = new List<string> { "shr-1", "shr-2", "shr-3", "shr-4" },
                SuggestedThemeIds = new List<string> { "theme-birthday-gold", "theme-birthday-neon" },
                TargetBudgetRangeMin = 4000f,
                TargetBudgetRangeMax = 10000f,
                UpsellNotes = "Personalize com itens adicionais.",
                DownsellNotes = "Para orçamento menor, veja Standard.",
                DisplayOrder = 5
            });

            // Business (tpl-3): Standard, Premium
            _packages.Add(new ProposalCommercialPackage
            {
                Id = "pkg-business-standard",
                Name = "Business Standard",
                Tier = CommercialPackageTier.Standard,
                Description = "Palco e mesas de reunião.",
                EventTemplateId = "tpl-3",
                IncludedShowroomItemIds = new List<string> { "shr-9", "shr-10" },
                SuggestedThemeIds = new List<string> { "theme-business-clean" },
                TargetBudgetRangeMin = 3500f,
                TargetBudgetRangeMax = 8000f,
                UpsellNotes = "Inclua coffee break e audiovisual (Premium).",
                DownsellNotes = "Pacote enxuto para reuniões.",
                DisplayOrder = 6
            });
            _packages.Add(new ProposalCommercialPackage
            {
                Id = "pkg-business-premium",
                Name = "Business Premium",
                Tier = CommercialPackageTier.Premium,
                Description = "Palco, mesas, coffee break e projetor/tela.",
                EventTemplateId = "tpl-3",
                IncludedShowroomItemIds = new List<string> { "shr-9", "shr-10", "shr-11", "shr-12" },
                SuggestedThemeIds = new List<string> { "theme-business-clean", "theme-business-premium" },
                TargetBudgetRangeMin = 8000f,
                TargetBudgetRangeMax = 20000f,
                UpsellNotes = "Personalize com mais itens ou upgrade de equipamentos.",
                DownsellNotes = "Para orçamento menor, veja Standard.",
                DisplayOrder = 7
            });
        }

        public ProposalCommercialPackage GetById(string packageId)
        {
            if (string.IsNullOrEmpty(packageId)) return null;
            return _packages.Find(p => p.Id == packageId);
        }

        public IReadOnlyList<ProposalCommercialPackage> GetByTemplateId(string templateId)
        {
            if (string.IsNullOrEmpty(templateId)) return new List<ProposalCommercialPackage>();
            return _packages.Where(p => p.EventTemplateId == templateId).OrderBy(p => p.DisplayOrder).ToList();
        }

        public IReadOnlyList<ProposalCommercialPackage> GetAvailableForProject(EventProject project)
        {
            if (project == null) return new List<ProposalCommercialPackage>();
            var templateId = project.EventTemplateId;
            return GetByTemplateId(templateId);
        }
    }
}
