using FluentValidation;
using GreenTree.Strohrmann.ERP.Domain.Model;
using GreenTree.Strohrmann.ERP.Web.Models.Business;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace GreenTree.Strohrmann.ERP.Web.Validators
{
	public class CraftMaterialValidator : AbstractValidator<KeyValuePair<string, CraftMaterialModel>>
	{
		#region DI fields

		// The global DbContext
		private readonly ERPDbContext _eRPDbContext;

		#endregion

		#region Ctor

		/// <summary>
		/// Initializes a new instance of the CraftMaterialValidator class
		/// </summary>
		/// <param name="eRPDbContext">Global DbContext.</param>
		public CraftMaterialValidator(
			ERPDbContext eRPDbContext)
		{
			_eRPDbContext = eRPDbContext;

			RuleFor(m => m.Value)
				.Custom((val, ctx) =>
				{
					if (val.MaterialId == 0)
						ctx.AddFailure("MaterialId", "Ein Material muss gewählt werden.");

					if (val.Amount <= 0)
						ctx.AddFailure(
							String.Format("CraftMaterials[{0}].Amount", val.DictIdentifier), "'Menge' muss größer als 0 sein.");

					if (val.CalculationFactor <= 0)
						ctx.AddFailure(
							String.Format("CraftMaterials[{0}].CalculationFactor", val.DictIdentifier), "'Kalkulationsfaktor' muss größer als 0 sein.");

					if (val.Value <= 0)
						ctx.AddFailure(
							String.Format("CraftMaterials[{0}].Value", val.DictIdentifier), "'Wert' muss größer als 0 sein.");
				});
		}

        #endregion
    }
}