using System;
using System.Windows;
using Machinations.FromFlash.machinations.model;
using Machinations.GUI;
using Machinations.UserComponents;

namespace Machinations.FromFlash.graph
{
       
    /// <summary>
    /// for creating connections after load
    /// </summary>
    public class GraphConnectionType
    {
        public string Name;
		public ConnectionClass ConnectionClass;
		
		
		public GraphConnectionType(ConnectionClass connectionClass, string name)
        {
            ConnectionClass = connectionClass;
            Name = name;
        }

        public static MachinationsConnection GetConnectionFromClass(ConnectionClass connectionClass, MergedConnectionKey? mcc = null)
        {
            if (mcc == null)
            {
                switch (connectionClass)
                {
                    case ConnectionClass.ResourceConnection:
                        return new ResourceConnection();
                    case ConnectionClass.StateConnection:
                        return new StateConnection();
                    //case ConnectionClass.GraphConnection:
                    //    return new GraphConnection();
                    default:
                        throw new ArgumentOutOfRangeException(nameof(connectionClass), connectionClass, null);
                }
            }
            else
            {
                switch (connectionClass)
                {
                    case ConnectionClass.ResourceConnection:
                        return new MergedResourceConnection(mcc.Value);
                    case ConnectionClass.StateConnection:
                        return new MergedStateConnection(mcc.Value);
                    //case ConnectionClass.GraphConnection:
                    //    return new GraphConnection();
                    default:
                        throw new ArgumentOutOfRangeException(nameof(connectionClass), connectionClass, null);
                }
            }
        }

        public static IConnectionView GetViewFromClass(MachinationsConnection connection, Point? startingPoint = null)
        {
            var resourceConnection = connection as ResourceConnection;
            if (resourceConnection != null) return new ResourceConnectionView(resourceConnection, startingPoint);
            var stateConnection = connection as StateConnection;
            if (stateConnection != null) return new StateConnectionView(stateConnection, startingPoint);
            throw new NotImplementedException();
        }
    }
}
