using Bolt;
using Ludiq;
using UnityEngine;

namespace InfinityCode.OnlineMapsBolt
{
    [UnitTitle("Subscribe To Marker Events")]
    [UnitSubtitle("(arg - marker)")]
    public class SubscribeToMarkerEvents : OnlineMapsBoltEventBase
    {
        [DoNotSerialize]
        public ValueInput marker { get; private set; }

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

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

        [DoNotSerialize]
        [PortLabel("Drag")]
        public ValueInput OnDrag;

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

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

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

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

        protected override void OnEnter(Flow flow)
        {
            OnlineMapsMarkerBase m = flow.GetValue<OnlineMapsMarkerBase>(marker);
            if (m == null)
            {
                Debug.Log("Marker is null");
                return;
            }

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