using Core.Abstractions.Models;
using Core.DomainObjects.Documents;
using Core.DomainObjects.L10n;
using Core.Enumerations;
using Extensions;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using WeatherForecast.Models.Requests.L10n;
namespace WeatherForecast.Models.Requests {
  /// 
  /// 
  /// 
  public class CategoryItemRequestModel : RequestModelBase {
    /// 
    /// 
    /// 
    public List? L10n { get; set; }
    /// 
    /// 
    /// 
    /// 
    public override Category ToDomainObject() {
      if (HasValidationErrors()) throw new ValidationException();
      
      return new Category() {
        L10n = L10n.Select(x => x.ToDomainObject()).ToList()
      };
    }
    /// 
    /// 
    /// 
    /// 
    /// 
    public override IEnumerable Validate(ValidationContext validationContext) {
      if (L10n.IsNullOrEmpty())
        yield return new ValidationResult($"{nameof(L10n)} ${Errors.NullOrEmpty}");
    }
    [MemberNotNullWhen(false, new[] { nameof(L10n) })]
    private bool HasValidationErrors() => Validate(new ValidationContext(this)).Any();
  }
}