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

namespace VetClinicDataBaseImplement.Models
{
	public class Guidance : IGuidanceModel
	{
		public int Id { get; private set; }
		[Required]
		public int ServiceId { get; private set; }
		public virtual Service Service { get; private set; }
		[Required]
		public string Text { get; private set; } = string.Empty;
		[Required]
		public DateTime Date { get; private set; }
		public static Guidance? Create(VetClinicDatabase context, GuidanceBindingModel model)
		{
			if (model == null)
			{
				return null;
			}
			return new Guidance()
			{
				Id = model.Id,
				ServiceId = model.ServiceId,
				Text = model.Text,
				Date = model.Date,
				Service = context.Services.FirstOrDefault(x => x.Id == model.ServiceId),
			};
		}

		public void Update(GuidanceBindingModel? model)
		{
			if (model == null)
			{
				return;
			}
			Text = model.Text;
			Date = model.Date;
		}

		public GuidanceViewModel GetViewModel => new()
		{
			ServiceId = ServiceId,
			Text = Text,
			Date = Date,
			Id = Id,
			ServiceName = Service.ServiceName
		};
	}
}
