using Core.Abstractions.Models;
using Core.DomainObjects;
using Core.Enumerations;
using WeatherForecast.Models.Responses.L10n;

namespace WeatherForecast.Models {

  /// <summary>
  /// 
  /// </summary>
  public class MediaAttachmentResponseModel : ResponseModelBase {

    /// <summary>
    /// 
    /// </summary>
    public List<MediaAttachmentL10nModel>? L10n { get; set; } 

    /// <summary>
    /// 
    /// </summary>
    public string? Src { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public string? Alt { get; set; }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="image"></param>
    public MediaAttachmentResponseModel(MediaAttachment image) {
      L10n = image.L10n.Select(x => new MediaAttachmentL10nModel(x)).ToList();
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="mediaAttachment"></param>
    /// <param name="locale"></param>
    public MediaAttachmentResponseModel(MediaAttachment mediaAttachment, Locales locale) {
      Src = mediaAttachment.Src;

      var l10n = mediaAttachment.L10n.Single(x => x.Locale == locale);

      if (l10n != null) {
        Alt = l10n.Alt;
      }
    }
  }
}
