using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace FishFactoryDatabaseImplement.Models
{
	[DataContract]
	public class MessageInfo : IMessageInfoModel
	{
		[DataMember]
		[Key]
		public string MessageId { get; private set; } = string.Empty;
		[DataMember]
		public int? ClientId { get; private set; }
		[DataMember]
		[Required]
		public string SenderName { get; private set; } = string.Empty;
		[DataMember]
		[Required]
		public DateTime DateDelivery { get; private set; } = DateTime.Now;
		[DataMember]
		[Required]
		public string Subject { get; private set; } = string.Empty;
		[DataMember]
		[Required]
		public string Body { get; private set; } = string.Empty;
		public virtual Client? Client { get; private set; } 
		public static MessageInfo? Create(MessageInfoBindingModel model)
		{
			if (model == null)
			{
				return null;
			}
			return new MessageInfo
			{
				MessageId = model.MessageId,
				ClientId = model.ClientId,
				SenderName = model.SenderName,
				Body = model.Body,
				DateDelivery = model.DateDelivery,
				Subject = model.Subject,
			};
		}

		public MessageInfoViewModel GetViewModel => new()
		{
			MessageId = MessageId,
			ClientId = ClientId,
			SenderName = SenderName,
			Body = Body,
			DateDelivery = DateDelivery,
			Subject = Subject,
		};
		public int Id => throw new NotImplementedException();
	}
}
