using OnlineMaps;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(OnlineMapsCategories.MARKERS)]
    [Tooltip("Remove 2D or 3D marker from map.")]
    public class RemoveMarker : FsmStateAction
    {
        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Instance of 2D or 3D marker.")]
        public FsmObject marker;

        public override void Reset()
        {
            marker = null;
        }

        public override void OnEnter()
        {
            DoEnter();
            Finish();
        }

        private void DoEnter()
        {
            if (!Map.instance)
            {
                Debug.LogError("Online Maps not found.");
                return;
            }

            if (marker.IsNone) return;

            if (marker.Value.GetType() != typeof(MarkerWrapper))
            {
                Debug.Log("Its not MarkerWrapper instance");
                return;
            }

            Marker m = (marker.Value as MarkerWrapper).marker;

            if (m is Marker2D) Marker2DManager.RemoveItem(m as Marker2D);
            else if (m is Marker3D) Marker3DManager.RemoveItem(m as Marker3D);
        }
    }
}