using System.Collections.Generic;
using EventsAppQuest.Application.Services;
using EventsAppQuest.Core;
using EventsAppQuest.Domain.Models;

namespace EventsAppQuest.Infrastructure.Services
{
    /// <summary>
    /// Implementacao mock: soma EstimatedPrice dos itens do showroom presentes no projeto.
    /// </summary>
    public class MockProposalPricingService : IProposalPricingService
    {
        public ProposalPricingSummary GetPricingSummary(EventProject project)
        {
            var summary = new ProposalPricingSummary { ItemCount = 0, TotalEstimated = 0f, SupplierCount = 0 };
            if (project?.ShowroomItemIds == null || project.ShowroomItemIds.Count == 0)
                return summary;

            var showroomService = ServiceRegistry.Instance.Get<IShowroomService>();
            if (showroomService == null) return summary;

            var supplierIds = new HashSet<string>();
            float total = 0f;

            foreach (var id in project.ShowroomItemIds)
            {
                var item = showroomService.GetById(id);
                if (item == null) continue;
                summary.ItemCount++;
                total += item.EstimatedPrice;
                if (!string.IsNullOrEmpty(item.SupplierId))
                    supplierIds.Add(item.SupplierId);
            }

            summary.TotalEstimated = total;
            summary.SupplierCount = supplierIds.Count;
            return summary;
        }
    }
}
