using Bolt;
using Ludiq;
using UnityEngine;

namespace InfinityCode.OnlineMapsBolt
{
    [UnitTitle("Subscribe To Drawing Element Events")]
    [UnitSubtitle("(arg - drawing element)")]
    public class SubscribeToDrawingElementEvents : OnlineMapsBoltEventBase
    {
        [DoNotSerialize]
        public ValueInput drawingElement { get; private set; }

        [DoNotSerialize]
        [PortLabel("Click")]
        public ValueInput OnClick;

        [DoNotSerialize]
        [PortLabel("Double Click")]
        public ValueInput OnDoubleClick;

        [DoNotSerialize]
        [PortLabel("Long Press")]
        public ValueInput OnLongPress;

        [DoNotSerialize]
        [PortLabel("Press")]
        public ValueInput OnPress;

        [DoNotSerialize]
        [PortLabel("Release")]
        public ValueInput OnRelease;

        protected override void OnDefinition()
        {
            drawingElement = ValueInput("drawingElement", (OnlineMapsMarkerBase)null);
            OnClick = ValueInput("OnClick", string.Empty);
            OnDoubleClick = ValueInput("OnDoubleClick", string.Empty);
            OnLongPress = ValueInput("OnLongPress", string.Empty);
            OnPress = ValueInput("OnPress", string.Empty);
            OnRelease = ValueInput("OnRelease", string.Empty);
        }

        protected override void OnEnter(Flow flow)
        {
            OnlineMapsDrawingElement d = flow.GetValue<OnlineMapsDrawingElement>(drawingElement);
            if (d == null)
            {
                Debug.Log("Drawing Element is null");
                return;
            }

            SubscribeToEvent(flow, ref d.OnClick, OnClick);
            SubscribeToEvent(flow, ref d.OnDoubleClick, OnDoubleClick);
            SubscribeToEvent(flow, ref d.OnLongPress, OnLongPress);
            SubscribeToEvent(flow, ref d.OnPress, OnPress);
            SubscribeToEvent(flow, ref d.OnRelease, OnRelease);
        }
    }
}