using Bolt;
using Ludiq;
using UnityEngine;

namespace InfinityCode.OnlineMapsBolt
{
    [UnitTitle("Subscribe To Tileset Events")]
    [UnitSubtitle("(arg - none)")]
    public class SubscribeToTilesetEvents : OnlineMapsBoltEventBase
    {
        [DoNotSerialize]
        [PortLabel("Camera Control")]
        public ValueInput OnCameraControl;

        [DoNotSerialize]
        [PortLabel("Mesh Updated")]
        public ValueInput OnMeshUpdated;

        [DoNotSerialize]
        [PortLabel("Smooth Zoom Begin")]
        public ValueInput OnSmoothZoomBegin;

        [DoNotSerialize]
        [PortLabel("Smooth Zoom Finish")]
        public ValueInput OnSmoothZoomFinish;

        [DoNotSerialize]
        [PortLabel("Smooth Zoom Init")]
        public ValueInput OnSmoothZoomInit;

        [DoNotSerialize]
        [PortLabel("Smooth Zoom Process")]
        public ValueInput OnSmoothZoomProcess;

        protected override void OnDefinition()
        {
            OnCameraControl = ValueInput("OnCameraControl", string.Empty);
            OnMeshUpdated = ValueInput("OnMeshUpdated", string.Empty);
            OnSmoothZoomBegin = ValueInput("OnSmoothZoomBegin", string.Empty);
            OnSmoothZoomFinish = ValueInput("OnSmoothZoomFinish", string.Empty);
            OnSmoothZoomInit = ValueInput("OnSmoothZoomInit", string.Empty);
            OnSmoothZoomProcess = ValueInput("OnSmoothZoomProcess", string.Empty);
        }

        protected override void OnEnter(Flow flow)
        {
            OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance;
            if (control == null)
            {
                Debug.Log("Tileset is null");
                return;
            }

            if (OnlineMapsCameraOrbit.instance != null) SubscribeToEvent(flow, ref OnlineMapsCameraOrbit.instance.OnCameraControl, OnCameraControl);
            SubscribeToEvent(flow, ref control.OnMeshUpdated, OnMeshUpdated);
            SubscribeToEvent(flow, ref control.OnSmoothZoomBegin, OnSmoothZoomBegin);
            SubscribeToEvent(flow, ref control.OnSmoothZoomFinish, OnSmoothZoomFinish);
            SubscribeToEvent(flow, ref control.OnSmoothZoomInit, OnSmoothZoomInit);
            SubscribeToEvent(flow, ref control.OnSmoothZoomProcess, OnSmoothZoomProcess);
        }
    }
}