using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace DatabaseImplement.Models
{
	public class Implementer : IImplementerModel
	{
		public int Id { get; set; }
		[Required]
		public string Email { get; set; } = string.Empty;
		[Required]
		public string Name { get; set; } = string.Empty;
		[Required]
		public string Login { get; set; } = string.Empty;
		[Required]
		public string Password { get; set;} = string.Empty;
		[ForeignKey("UserId")]
		public virtual List<Detail> Details { get; set; } = new();
		[ForeignKey("UserId")]
		public virtual List<Product> Products { get; set; } = new();
		[ForeignKey("UserId")]
		public virtual List<Production> Productions { get; set; } = new();

		public static Implementer? Create(ImplementerBindingModel model)
		{
			if (model == null)
			{
				return null;
			}
			return new Implementer
			{
				Id = model.Id,
				Email = model.Email,
				Name = model.Name,
				Login = model.Login,
				Password = model.Password
			};
		}
		public static Implementer Create(ImplementerViewModel model)
		{
			return new Implementer
			{
				Id = model.Id,
				Email = model.Email,
				Name = model.Name,
				Login = model.Login,
				Password = model.Password
			};
		}
		public void Update(ImplementerBindingModel model)
		{
			if (model == null)
				return;
			Email = model.Email;
			Name = model.Name;
			Password = model.Password;
		}
		public ImplementerViewModel GetViewModel => new()
		{
			Id = Id,
			Email = Email,
			Name = Name,
			Login = Login,
			Password = Password
		};

	}
}