﻿using Bolt;
using Ludiq;
using UnityEngine;

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

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

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