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 CraftEmployeeValidator : AbstractValidator<KeyValuePair<string, CraftEmployeeModel>>
	{
		#region DI fields

		// The global DbContext
		private readonly ERPDbContext _eRPDbContext;

		#endregion

		#region Ctor

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

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

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

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

        #endregion
    }
}