﻿using Bolt;
using Ludiq;
using UnityEngine;

namespace InfinityCode.OnlineMapsBolt
{
    [UnitTitle("Reset Cache Events")]
    public class ResetCacheEvents : OnlineMapsBoltEventBase
    {
        [DoNotSerialize]
        [PortLabel("Loaded From Cache")]
        public ValueInput OnLoadedFromCache;

        [DoNotSerialize]
        [PortLabel("Loaded From File Cache")]
        public ValueInput OnLoadedFromFileCache;

        protected override void OnDefinition()
        {
            OnLoadedFromCache = ValueInput("OnLoadedFromCache", false);
            OnLoadedFromFileCache = ValueInput("OnLoadedFromFileCache", false);
        }

        protected override void OnEnter(Flow flow)
        {
            OnlineMapsCache cache = OnlineMapsCache.instance;
            if (cache == null)
            {
                Debug.Log("Cache is null");
                return;
            }

            if (flow.GetValue<bool>(OnLoadedFromCache)) cache.OnLoadedFromCache = null;
            if (flow.GetValue<bool>(OnLoadedFromFileCache)) cache.OnLoadedFromFileCache = null;
        }
    }
}