﻿using System.Collections.Generic;
using Microsoft.Extensions.Configuration;

namespace SimpleSmtp.Core.Config
{
	internal class ConfigService : IConfigService
	{
		public IEnumerable<int> Ports { get; set; }

		public int ReceiveTimeout { get; set; }

		public int SendTimeout { get; set; }

		public IEnumerable<string> LocalDomains { get; set; }

		public IEnumerable<FeedbackAddress> FeedbackAddresses { get; set; }

		public IEnumerable<string> AllowedRelayIpAddresses { get; set; }

		public string MailboxLocation { get; set; }

		public ConfigService(IConfigurationRoot config)
		{
			Guard.NotNull(config, nameof(config));

			ReceiveTimeout = 30;
			SendTimeout = 30;

			config.GetSection("settings").Bind(this);

			if (LocalDomains == null)
				LocalDomains = new List<string>();
			if (FeedbackAddresses == null)
				FeedbackAddresses = new List<FeedbackAddress>();
			if (AllowedRelayIpAddresses == null)
				AllowedRelayIpAddresses = new List<string>();
		}
	}
}