using System;
using StandardScene.Signal.Model;

namespace StandardScene.Signal.Logic
{
    /// <summary>握手点解析结果。参数格式与反编译 SignalStop.SignalParams 一致。</summary>
    public sealed class SignalStopSpec
    {
        public string SignalType { get; init; } = "";
        public string SignalParams { get; init; } = "";
        public string[] Parts { get; init; } = Array.Empty<string>();

        public string Part(int index)
        {
            if (index < 0 || index >= Parts.Length)
                return "";
            return Parts[index] ?? "";
        }

        public static SignalStopSpec Parse(string signalType, string signalParams)
        {
            var type = (signalType ?? "").Trim();
            var raw = signalParams ?? "";
            return new SignalStopSpec
            {
                SignalType = type,
                SignalParams = raw,
                Parts = raw.Split(new[] { ';' }, StringSplitOptions.None)
            };
        }

        public static SignalStopSpec From(HandshakePointModel model)
        {
            if (model == null)
                return null;
            return Parse(model.SignalType, model.SignalParams);
        }

        public bool Is(string type) =>
            string.Equals(SignalType, type, StringComparison.OrdinalIgnoreCase);
    }
}
