using TakeoutSaaS.Application.App.Products.Dto;
using TakeoutSaaS.Domain.Products.Entities;

namespace TakeoutSaaS.Application.App.Products;

/// <summary>
/// 商品标签 DTO 映射工厂。
/// </summary>
internal static class ProductLabelDtoFactory
{
    /// <summary>
    /// 将标签实体映射为页面 DTO。
    /// </summary>
    public static ProductLabelItemDto ToDto(
        ProductLabel label,
        IReadOnlyDictionary<long, int> productCounts)
    {
        var productCount = productCounts.TryGetValue(label.Id, out var count)
            ? count
            : 0;

        return new ProductLabelItemDto
        {
            Id = label.Id,
            Name = label.Name,
            Color = label.Color,
            Sort = label.SortOrder,
            Status = ProductLabelMapping.ToStatusText(label.IsEnabled),
            ProductCount = productCount,
            UpdatedAt = label.UpdatedAt ?? label.CreatedAt
        };
    }
}
