using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TIAM.Entities.Emails;
using TIAM.Resources;

namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
{
    public class MessageWizardModel
    {
       
        public string ReceiverEmailAddress { get; set; }
        public Guid ReceiverId { get; set; }
        public string SenderEmailAddress { get; set; }
        public Guid SenderId { get; set; }
        public Guid ContextId { get; set; }
        [Required(ErrorMessage = "The subject value should be specified.")]
        [DataType(DataType.Text)]
        [Display(Name = "Subject", ResourceType = typeof(TIAMResources))]
        public string Subject { get; set; }
        [Required(ErrorMessage = "The content value should be specified.")]
        [DataType(DataType.MultilineText)]
        [Display(Name = "HtmlContent", ResourceType = typeof(TIAMResources))]
        public string Content { get; set; }

        public MessageWizardModel() { }
        public MessageWizardModel(string receiverEmailAddress, Guid receiverId, string senderEmailAddress, Guid senderId, string subject, string content)
        {
            ReceiverEmailAddress = receiverEmailAddress;
            ReceiverId = receiverId;
            SenderEmailAddress = senderEmailAddress;
            SenderId = senderId;
            Subject = subject;
            Content = content;
        }

        public static EmailMessage ConvertToNewEmailMessage(MessageWizardModel message)
        {
            var id = Guid.NewGuid();
       

            return new EmailMessage
            {
                Id = id,                
                SenderId = message.SenderId,
                ContextId = message.ContextId,
                Subject = message.Subject,
                Text = message.Content,
                SenderEmailAddress = message.SenderEmailAddress,
                Recipients = new List<EmailRecipient> { new EmailRecipient(
                    Guid.NewGuid(), message.ReceiverId, id) }            
            };
        }
    }    
}
