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

namespace VeterinaryDatabaseImplement.Models
{
    public class Medication : IMedicationModel
	{
		public int Id { get; private set; }
		[Required]
		public string MedicationName { get; private set; } = string.Empty;
		[Required]
		public double Price { get; set; }
		[Required]
		public int DoctorId { get; private set; }
		[ForeignKey("MedicationId")]
		public virtual List<ServiceMedication> ServiceMedications { get; set; } = new();
		[ForeignKey("MedicationId")]
		public virtual List<DrugMedication> DrugMedications { get; set; } = new();
		
		public static Medication? Create(MedicationBindingModel model)
		{
			if (model == null)
			{
				return null;
			}
			return new Medication()
			{
				Id = model.Id,
				MedicationName = model.MedicationName,
				DoctorId = model.DoctorId,
				Price = model.Price
			};
		}
		public static Medication Create(MedicationViewModel model)
		{
			return new Medication
			{
				Id = model.Id,
				MedicationName = model.MedicationName,
				DoctorId = model.DoctorId,
				Price = model.Price
			};
		}
		public void Update(MedicationBindingModel model)
		{
			if (model == null)
			{
				return;
			}
			MedicationName = model.MedicationName;
			Price = model.Price;
		}
		public MedicationViewModel GetViewModel => new()
		{
			Id = Id,
			MedicationName = MedicationName,
			Price = Price,
			DoctorId = DoctorId
		};
	}
}
