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;
using System.Collections;
using System.ComponentModel;

namespace VetClinicDataBaseImplement.Models
{
	public class Animal : IAnimalModel
	{
		public int Id { get; set; }
		[Required]
		public int AdminId { get; set; }

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

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


		[ForeignKey("AnimalId")]
		public virtual List<Vaccination> Vaccinations { get; set; } = new();

		public virtual Admin Admin { get; set; }

		[ForeignKey("AnimalId")]
		public virtual List<VisitAnimal> Visits { get; set; } = new();


		[ForeignKey("AnimalId")]
		public virtual List<MedicineAnimal> Medicines { get; set; } = new();
		
		public static Animal? Create(VetClinicDatabase context, AnimalBindingModel? model)
		{
			if (model == null)
			{
				return null;
			}
			return new Animal()
			{
				Id = model.Id,
				AdminId = model.AdminId,
				AnimalName = model.AnimalName,
				Family = model.Family,
			
			};
		}
		public void Update(AnimalBindingModel? model)
		{
			if (model == null)
			{
				return;
			}
			AnimalName = model.AnimalName;
			Family = model.Family;
		}
		public AnimalViewModel GetViewModel => new()
		{
			Id = Id,
			AdminId = AdminId,
			AnimalName = AnimalName,
			Family = Family

		};
		
	}
}
