using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Villain.Data;

namespace Fiesta.Config
{
	public sealed class DatabaseInfo : Dictionary<string, DatabaseInfo.Info>
	{
		public static DatabaseInfo Load(string path)
		{
			DatabaseInfo databaseInfo = new DatabaseInfo();

			Dictionary<string, Info> infos = new Dictionary<string, Info>();

			infos = JSON.Deserialize<Dictionary<string, Info>>(File.ReadAllText(path));

			if (infos != null)
			{
				foreach (KeyValuePair<string, Info> info in infos)
				{
					databaseInfo.Add(info.Key, info.Value);
				}
			}

			return databaseInfo;
		}

		public string Serialize()
		{
			return JSON.Serialize(this);
		}

		public class Info
		{
			public string Host = "";
			public string Username = "";
			public string Password = "";
			public string Database = "";
		}
	}
}