﻿using Bolt;
using Ludiq;
using UnityEngine;

namespace InfinityCode.OnlineMapsBolt
{
    [UnitTitle("Reset TextWebService Events")]
    public class ResetTextWebServiceEvents : OnlineMapsBoltEventBase
    {
        [DoNotSerialize]
        public ValueInput request { get; private set; }

        [DoNotSerialize]
        [PortLabel("Complete")]
        public ValueInput OnComplete;

        [DoNotSerialize]
        [PortLabel("Success")]
        public ValueInput OnSuccess;

        [DoNotSerialize]
        [PortLabel("Failed")]
        public ValueInput OnFailed;

        protected override void OnDefinition()
        {
            request = ValueInput("request", (OnlineMapsTextWebService)null);
            OnComplete = ValueInput("OnComplete", false);
            OnSuccess = ValueInput("OnSuccess", false);
            OnFailed = ValueInput("OnFailed", false);
        }

        protected override void OnEnter(Flow flow)
        {
            OnlineMapsTextWebService r = flow.GetValue<OnlineMapsTextWebService>(request);
            if (r == null)
            {
                Debug.Log("Request is null");
                return;
            }

            if (flow.GetValue<bool>(OnComplete)) r.OnComplete = null;
            if (flow.GetValue<bool>(OnSuccess)) r.OnSuccess = null;
            if (flow.GetValue<bool>(OnFailed)) r.OnFailed = null;
        }
    }
}