using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
using static System.Runtime.InteropServices.JavaScript.JSType;
using VetClinicContracts.BindingModels;
using VetClinicContracts.ViewModels;
using VetClinicDataModels.Models;

namespace VetClinicDataBaseImplement.Models
{
	public class Vaccination : IVaccinationModel
	{
		public int Id { get; set; }
		[Required]
		public int AnimalId { get; set; }
		public virtual Animal Animal { get; set; }
		[Required]
		public string NameVaccination { get; set; } = string.Empty;
		[Required]
		public double CostVaccination { get; set; }
		[Required]
		public DateTime DateStamp { get; set; }
		public static Vaccination? Create(VetClinicDatabase context, VaccinationBindingModel? model)
		{
			if (model == null)
			{
				return null;
			}
			return new Vaccination()
			{
				Id = model.Id,
				AnimalId = model.AnimalId,
				NameVaccination = model.NameVaccination,
				CostVaccination = model.CostVaccination,
				DateStamp = model.DateStamp,
				Animal = context.Animals.FirstOrDefault(x => x.Id == model.AnimalId)
			};
		}

		public void Update(VetClinicDatabase context, VaccinationBindingModel? model)
		{
			if (model == null)
			{
				return;
			}
			NameVaccination = model.NameVaccination;
			CostVaccination = model.CostVaccination;
			DateStamp = model.DateStamp;
			AnimalId = model.AnimalId;
			Animal = context.Animals.FirstOrDefault(x => x.Id == model.AnimalId);
		}
	
		public VaccinationViewModel GetViewModel => new()
		{
			Id = Id,
			AnimalId = AnimalId,
			NameVaccination = NameVaccination,
			CostVaccination = CostVaccination,
			DateStamp = DateStamp,
			AnimalName = Animal.AnimalName
		};
	}
}
