using System;
using System.Collections.Generic;
using System.Linq;
using Machinations.FromFlash.graph;

namespace Machinations.FromFlash.machinations.model
{
    /// <summary>
    /// Static class for getting element types out of saved strings
    /// </summary>
    public static class MachinationsGrammar
    {
        public static List<GraphSymbol> Symbols = new List<GraphSymbol>
        {
            new GraphSymbol(NodeClass.Pool, "Pool"),
            new GraphSymbol(NodeClass.Gate, "Gate"),
            new GraphSymbol(NodeClass.Source, "Source"),
            new GraphSymbol(NodeClass.Drain, "Drain"),
            new GraphSymbol(NodeClass.Converter, "Converter"),
            new GraphSymbol(NodeClass.Trader, "Trader"),
            new GraphSymbol(NodeClass.EndCondition, "EndCondition"),
            new GraphSymbol(NodeClass.Register, "Register"),
            new GraphSymbol(NodeClass.Delay, "Delay"),
            new GraphSymbol(NodeClass.ArtificialPlayer, "ArtificialPlayer"),
            new GraphSymbol(NodeClass.TextLabel, "TextLabel"),
            new GraphSymbol(NodeClass.GroupBox, "GroupBox"),
            new GraphSymbol(NodeClass.InOut, "InOut"),
            new GraphSymbol(NodeClass.InnerInOut, "InnerInOut"),
            new GraphSymbol(NodeClass.OuterInOut, "OuterInOut")
        };

        public static List<GraphConnectionType> ConnectionTypes = new List<GraphConnectionType>
        {
            new GraphConnectionType(ConnectionClass.ResourceConnection, "Resource Connection"),
            new GraphConnectionType(ConnectionClass.StateConnection, "State Connection")
        };

        public static GraphConnectionType GetConnectionType(string name)
        {
            return
                ConnectionTypes.SingleOrDefault(
                    con => con.Name.Replace(" ", "").Equals(name.Replace(" ", ""), StringComparison.OrdinalIgnoreCase));
        }

        public static GraphSymbol GetSymbol(string name)
        {
            var symbol = Symbols.SingleOrDefault(s => s.Name == name);
            if (symbol != null)
                return symbol;
            throw new UnsupportedElementException(name);
        }
    }
}
