﻿using Bolt;
using Ludiq;
using UnityEngine;

namespace InfinityCode.OnlineMapsBolt
{
    [UnitTitle("Reset Location Service Events")]
    public class ResetLocationServiceEvents : OnlineMapsBoltEventBase
    {
        [DoNotSerialize]
        [PortLabel("Compass Changed")]
        public ValueInput OnCompassChanged;

        [DoNotSerialize]
        [PortLabel("Find Location By IP Complete")]
        public ValueInput OnFindLocationByIPComplete;

        [DoNotSerialize]
        [PortLabel("Location Changed")]
        public ValueInput OnLocationChanged;

        [DoNotSerialize]
        [PortLabel("Location Inited")]
        public ValueInput OnLocationInited;

        [DoNotSerialize]
        [PortLabel("Position Restored")]
        public ValueInput OnPositionRestored;

        protected override void OnDefinition()
        {
            OnCompassChanged = ValueInput("OnCompassChanged", false);
            OnFindLocationByIPComplete = ValueInput("OnFindLocationByIPComplete", false);
            OnLocationChanged = ValueInput("OnLocationChanged", false);
            OnLocationInited = ValueInput("OnLocationInited", false);
            OnPositionRestored = ValueInput("OnPositionRestored", false);
        }

        protected override void OnEnter(Flow flow)
        {
            OnlineMapsLocationServiceBase ls = OnlineMapsLocationServiceBase.baseInstance;

            if (ls == null)
            {
                Debug.Log("Online Maps Location Service is null");
                return;
            }

            if (flow.GetValue<bool>(OnCompassChanged)) ls.OnCompassChanged = null;
            if (flow.GetValue<bool>(OnFindLocationByIPComplete)) ls.OnFindLocationByIPComplete = null;
            if (flow.GetValue<bool>(OnLocationChanged)) ls.OnLocationChanged = null;
            if (flow.GetValue<bool>(OnLocationInited)) ls.OnLocationInited = null;
            if (flow.GetValue<bool>(OnPositionRestored)) ls.OnPositionRestored = null;
        }
    }
}