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

namespace VetClinicDataBaseImplement.Models
{
	public class Admin : IAdminModel
	{
		public int Id { get; set; }

		[Required]
		public string AdminFIO { get; set; } = string.Empty;

		[Required]
		public string Email { get; set; } = string.Empty;

		[Required]
		public string Password { get; set; } = string.Empty;

		[ForeignKey("AdminId")]
		public virtual List<Visit> Visits { get; set; } = new();
		[ForeignKey("AdminId")]
		public virtual List<Animal> Animals { get; set; } = new();
		public static Admin? Create(AdminBindingModel model)
		{
			if (model == null)
			{
				return null;
			}
			return new Admin()
			{
				Id = model.Id,
				AdminFIO = model.AdminFIO,
				Email = model.Email,
				Password = model.Password
			};
		}

		public static Admin Create(AdminViewModel model)
		{
			return new Admin
			{
				Id = model.Id,
				AdminFIO = model.AdminFIO,
				Email = model.Email,
				Password = model.Password
			};
		}

		public void Update(AdminBindingModel model)
		{
			if (model == null)
			{
				return;
			}
			AdminFIO = model.AdminFIO;
			Email = model.Email;
			Password = model.Password;
		}

		public AdminViewModel GetViewModel => new()
		{
			Id = Id,
			AdminFIO = AdminFIO,
			Email = Email,
			Password = Password
		};
	}
}
