﻿using Bolt;
using Ludiq;
using UnityEngine;

namespace InfinityCode.OnlineMapsBolt
{
    [UnitTitle("Reset Marker Events")]
    public class ResetMarkerEvents : 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", false);
            OnDoubleClick = ValueInput("OnDoubleClick", false);
            OnDrag = ValueInput("OnDrag", false);
            OnLongPress = ValueInput("OnLongPress", false);
            OnPress = ValueInput("OnPress", false);
            OnRelease = ValueInput("OnRelease", false);
        }

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

            if (flow.GetValue<bool>(OnClick)) m.OnClick = null;
            if (flow.GetValue<bool>(OnDoubleClick)) m.OnDoubleClick = null;
            if (flow.GetValue<bool>(OnDrag)) m.OnDrag = null;
            if (flow.GetValue<bool>(OnLongPress)) m.OnLongPress = null;
            if (flow.GetValue<bool>(OnPress)) m.OnPress = null;
            if (flow.GetValue<bool>(OnRelease)) m.OnRelease = null;
        }
    }
}