﻿/*
 * Created by SharpDevelop.
 * User: tenny.hasegawa
 * Date: 10/1/2015
 * Time: 12:02 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Mail;
using System.Xml.Serialization;

namespace RpsTk4.Email
{
    /// <summary>
    /// Rps Email Client Settings
    /// Settings to use with RpsEmailClient
    /// Normal Settings Needed: Smtp Host, From Email Address
    /// </summary>
    public class RpsEmailHostSettings
    {
        public string smtpHost { get; set; }

        public string fromEmail { get; set; }

        public double delaySecs { get; set; }
        public bool enableSsl { get; set; }

        /// <summary>
        /// Default Constructor:
        /// delay 3 seconds
        /// enable ssl = false; 
        /// </summary>
        public RpsEmailHostSettings()
        {
            delaySecs = 3.0;
            enableSsl = false;
        }

        /// <summary>
        /// Constructor with SMTP host and From Email
        /// </summary>
        /// <param name="smtphost"></param>
        /// <param name="fromemail"></param>
        public RpsEmailHostSettings(string smtphost, string fromemail)
            : this()
        {
            this.smtpHost = smtphost;
            this.fromEmail = fromemail;
        }

        public int getTimeout()
        {
            return (int)delaySecs * 1000;
        }

        /// <summary>
        /// Validate if all of the Email Client Settings are correct.
        /// Error Check Return (EC)
        /// Error Message Returned as Out String
        /// </summary>
        /// <param name="msg">out Error Message</param>
        /// <returns>bool Error Check Return (EC):  True if error, False if No Error</returns>
        public bool ValSettings_EC(out string errMsg)
        {
            errMsg = "";

            bool isErr = true;

            if (string.IsNullOrEmpty(this.smtpHost))
            {
                errMsg = "No SMTP Host Defined";
                return isErr;
            }

            if (string.IsNullOrEmpty(this.fromEmail))
            {
                errMsg = "No From Email Defined";
                return isErr;
            }
            isErr = false;
            return isErr;
        }
    }
}
