﻿using Bolt;
using Ludiq;
using UnityEngine;

namespace InfinityCode.OnlineMapsBolt
{
    [UnitTitle("Subscribe To WWW Events")]
    [UnitSubtitle("(arg - www)")]
    public class SubscribeToWWWEvents : OnlineMapsBoltEventBase
    {
        [DoNotSerialize]
        public ValueInput www { get; private set; }

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

        protected override void OnDefinition()
        {
            www = ValueInput("www", (OnlineMapsWWW)null);
            OnComplete = ValueInput("OnComplete", string.Empty);
        }

        protected override void OnEnter(Flow flow)
        {
            OnlineMapsWWW w = flow.GetValue<OnlineMapsWWW>(www);
            if (w != null) SubscribeToEvent(flow, ref w.OnComplete, OnComplete);
            else Debug.Log("WWW is null");
        }
    }
}