using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace MEU.API.Services.Emails.Templates
{
    public class EmailForgotPassword:EmailContent
    {
        protected string _Link = "";
        protected string _Username = "";

        public EmailForgotPassword(string EmailSubject, string Link, string Username, string RecieverUser)
        {
            this.EmailTemplatePath += "/EmailForgotPassword.html";
            _Link = Link;
            _Username = Username;
            this.Reciever = RecieverUser;
            this.Subject = EmailSubject;
        }

        public override string GetContent()
        {
            string fullBody = "Đây là link cập nhật mật khẩu {{link}} for user {{username}}";
            if (File.Exists(this.EmailTemplatePath))
            {
                fullBody = File.ReadAllText(this.EmailTemplatePath);
            }
            else
            {
                fullBody += "\r\nCannot find template email at path:" + this.EmailTemplatePath;
            }
           // 
            fullBody = fullBody.Replace("{{link}}", this._Link);
            fullBody = fullBody.Replace("{{username}}", this.Reciever);
            return fullBody;
        }

        public override bool Send()
        {
            this.SendEmail(this.Reciever, this.Subject, this.GetContent());
            return true;
        }

        public override async Task SendAsync()
        {
            await Task.Run(() => this.SendEmailAsync(this.Reciever, this.Subject, this.GetContent()));
        }
    }
}
