using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SchoolContracts.BindingModels;
using SchoolContracts.Models;
using SchoolContracts.ViewModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace SchoolDatabase.Models
{
	public class Custumer : ICustumerModel
	{
		public int Id { get; private set; }
		[Required]
		public string Login { get; private set; } = string.Empty;
		[Required]
		public string Password { get; private set; } = string.Empty;
		[Required]
		public string FIO { get; private set; } = string.Empty;
		[Required]
		
		// Обучение
		[ForeignKey("CustomerId")]
		public virtual List<Study> Study { get; set; } = new();
		public static Custumer? Create(CustomerBindingModel? model)
		{
			if (model == null)
			{
				return null;
			}
			return new()
			{
				Id = model.Id,
				Login = model.Login,
				Password = model.Password,
				FIO = model.FIO,
			};
		}
		public static Custumer Create(CustumerViewModel model)
		{
			return new()
			{
				Id = model.Id,
				Login = model.Login,
				Password = model.Password,
				FIO = model.FIO
			};
		}
		public void Update(CustomerBindingModel? model)
		{
			if (model == null)
			{
				return;
			}
			Login = model.Login;
			Password = model.Password;
			FIO = model.FIO;
		}
		public CustumerViewModel GetViewModel => new()
		{
			Id = Id,
			Login = Login,
			Password = Password,
			FIO = FIO
		};
	}
}
