using System.ComponentModel.DataAnnotations;

using Core.Abstractions.Models;
using Core.Enumerations;
using DomainObjects.Documents;


namespace WeatherForecast.Models.Shop.Requests {

  /// <summary>
  /// 
  /// </summary>
  public class ShopCartItemRequestModel : RequestModelBase<ShopCartDocument> {

    /// <summary>
    /// 
    /// </summary>
    public uint? Quantity { get; set; }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public override ShopCartDocument ToDomainObject() {

      return new ShopCartDocument() {
        Quantity = Quantity.Value,
        Created = DateTime.UtcNow
      };
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="validationContext"></param>
    /// <returns></returns>
    public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
      if (Quantity == null || (Quantity != null && Quantity == 0))
        yield return new ValidationResult($"{nameof(Quantity)} {Errors.NullOrEmpty}");
    }
  }
}
