using Core.Abstractions.Models;
using DomainObjects.Documents;
using Core.Enumerations;
using Extensions;
using System.ComponentModel.DataAnnotations;

namespace WeatherForecast.Models.Category.Requests {

  /// <summary>
  /// 
  /// </summary>
  public class CategoryItemRequestModel : RequestModelBase<CategoryDocument> {

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

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public override CategoryDocument ToDomainObject() {
      
      return new CategoryDocument() {
        L10n = L10n.Select(x => x.ToDomainObject()).ToList()
      };
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="validationContext"></param>
    /// <returns></returns>
    public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
      if (L10n.IsNullOrEmpty())
        yield return new ValidationResult($"{nameof(L10n)} ${Errors.NullOrEmpty}");
    }
  }
}
