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

namespace WeatherForecast.Models.Responses {

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

    /// <summary>
    /// 
    /// </summary>
    public Guid Id { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public Guid SiteId { get; set; }

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

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

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

    /// <summary>
    /// 
    /// </summary>
    /// <param name="category"></param>
    public CategoryItemResponseModel(Category category) {
      Id = category.Id;
      SiteId = category.SiteId;

      L10n = category.L10n.Select(x => new CategoryL10nModel(x)).ToList();
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="category"></param>
    /// <param name="locale"></param>
    public CategoryItemResponseModel(Category category, Locales locale) {
      Id = category.Id;
      SiteId = category.SiteId;

      var l10n = category.L10n.SingleOrDefault(x => x.Locale == locale);
      if (l10n != null) {
        Slug = l10n.Slug;
        Text = l10n.Text;
      }
    }
  }
}
