using OnlineMaps;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(OnlineMapsCategories.MARKERS)]
    [Tooltip("Sets 3D marker size type.")]
    public class Set3DMarkerSizeType : FsmStateAction
    {
        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Instance of marker.")]
        public FsmObject marker;

        [RequiredField]
        [Tooltip("Size type.")]
        public Marker3D.SizeType sizeType;

        public override void Reset()
        {
            marker = null;
            sizeType = Marker3D.SizeType.scene;
        }

        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;
            }

            Marker3D m = (marker.Value as MarkerWrapper).marker as Marker3D;
            if (m == null) return;

            m.sizeType = sizeType;
        }
    }
}