using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace EmpForm.Models {
	public enum Poste {
		Chef,
		SousChef,
		Grouillot,
	}
	public class Employe {

		[Required(ErrorMessage = "Le champ {0} est obligatoire !")]
		[Display(Name = "N° de membre du personnel")]
		[CustomValidation(typeof(Validations), "ValiderEmployeId")]
		public int ID { get; set; }

		[Required(ErrorMessage = "Le champ {0} est obligatoire !")]
		[Display(Name = "Prénom NOM")]
		[StringLength(50, MinimumLength = 2)]
		[RegularExpression(@"^[A-Z][a-z]*(-[A-Z][a-z]*)? [A-Z]+$", ErrorMessage = "ça correspond pas a ^[A-Z][a-z]*(-[A-Z][a-z]*)? [A-Z]+$")]
		public string Nom { get; set; }

		[Required(ErrorMessage = "Le champ {0} est obligatoire !")]
		public Poste Poste { get; set; }

		[Required(ErrorMessage = "Le champ {0} est obligatoire !")]
		[Range(0, 7000, ErrorMessage = "Un salaire conforme a la politique de l entreprise!")]
		public Decimal Salaire { get; set; }

		public static class Validations {
			public static ValidationResult ValiderEmployeId(int id) {
				if (id % 2 == 1) {
					return new ValidationResult($"Valeur {id} non-autorisee");
				}
				return null;
			}
		}
	}
}