using System.Collections.Generic;
using System.Windows;

namespace Nodify.Calculator.Models
{
    public class SaveGraphModel
    {
        public int Id { get; set; } = 1;
        public List<NodeData> Nodes { get; set; } = new List<NodeData>();
        public List<ConnectionData> Connections { get; set; } = new List<ConnectionData>();
    }

    public class NodeData
    {
        /// <summary>Unique ID matching OperationViewModel.NodeId</summary>
        public string NodeId { get; set; } = string.Empty;

        /// <summary>Discriminator: "API", "System", "Expando", "Calculator", "Function"</summary>
        public string NodeType { get; set; } = string.Empty;

        public string Title { get; set; } = string.Empty;
        public double LocationX { get; set; }
        public double LocationY { get; set; }

        // API node properties
        public string OPType { get; set; } = string.Empty;
        public string ResponseModelClassName { get; set; } = string.Empty;

        // System node properties
        public string SystemOp { get; set; } = string.Empty;
        public string ClassName { get; set; } = string.Empty;

        // Take node properties
        public int NthIndex { get; set; }
        public bool IsRandom { get; set; }

        // Function node properties
        public string FunctionName { get; set; } = string.Empty;
        public List<FunctionParamData> FunctionInputs { get; set; } = new List<FunctionParamData>();
        public List<FunctionParamData> FunctionOutputs { get; set; } = new List<FunctionParamData>();

        /// <summary>Saved input connector metadata (for dynamic nodes like SPLIT/COPY/TAKE)</summary>
        public List<ConnectorData> InputConnectors { get; set; } = new List<ConnectorData>();
        /// <summary>Saved output connector metadata</summary>
        public List<ConnectorData> OutputConnectors { get; set; } = new List<ConnectorData>();
    }

    public class ConnectorData
    {
        public string Title { get; set; } = string.Empty;
        public string Shape { get; set; } = "Circle";
        public int ColorArgb { get; set; }
        public string DataType { get; set; } = string.Empty;
        public bool IsCopyConnector { get; set; }
        public bool IsTakeListConnector { get; set; }
    }

    public class ConnectionData
    {
        public string SourceNodeId { get; set; } = string.Empty;
        public int SourceConnectorIndex { get; set; }
        public string TargetNodeId { get; set; } = string.Empty;
        public int TargetConnectorIndex { get; set; }
    }

    public class FunctionParamData
    {
        public string Name { get; set; } = string.Empty;
        public string Type { get; set; } = string.Empty;
    }

    // Keep legacy for compatibility
    public class SaveNodes
    {
        public Point Location { get; set; }
    }
}
