using TeleWave.Domain.Broadcast;

namespace TeleWave.Application.Broadcast.Bumpers;

/// <summary>Ручной маппинг блока заставки в DTO — одна точка на список и на карточку.</summary>
public static class BumperMapper
{
    public static BumperTemplateDto ToDto(BumperTemplate template, int usageCount) =>
        new(
            template.Id,
            template.Name,
            template.Font,
            template.BackgroundColor,
            template.BackgroundColor2,
            template.AccentColor,
            template.TextColor,
            template.BackgroundImageId,
            template.AudioExtension is not null,
            template.AudioDurationSeconds,
            usageCount,
            template
                .Variants.OrderBy(v => v.Position)
                .Select(v => new BumperTextVariantDto(
                    v.Id,
                    v.Position,
                    v.Name,
                    v.Trigger,
                    v.Background,
                    v.Weight,
                    v.Lines.OrderBy(l => l.Position)
                        .Select(l => new BumperLineDto(l.Style, l.Color, l.Text))
                        .ToList(),
                    v.BackgroundClipShowId
                ))
                .ToList()
        );
}
