﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HutongGames.PlayMaker.Actions;
using HutongGames.PlayMaker;
using Tooltip = HutongGames.PlayMaker.TooltipAttribute;

namespace Bayat.SaveSystem.PlayMaker
{

    [ActionCategory(SaveSystemAction.ActionCategoryName)]
    [Tooltip("Saves the value to the storage.")]
    public class SaveSystemSaveAction : SaveSystemSettingsAction
    {

        [Tooltip("The unique identifier for this value.")]
        public FsmString identifier;
        [Tooltip("The value to save.")]
        [UIHint(UIHint.Variable)]
        public FsmVar value;

        public override void OnReset()
        {
            this.identifier = "hello-world";
            this.value = null;
        }

        public override void Enter()
        {
            this.value.UpdateValue();
            if (this.settingsPreset)
            {
                SaveSystemAPI.SaveAsync(this.identifier.Value, this.value.GetValue(), this.settingsPreset.CustomSettings).ContinueWith(HandleTask);
            }
            else
            {

                SaveSystemAPI.SaveAsync(this.identifier.Value, this.value.GetValue()).ContinueWith(HandleTask);
            }
        }

    }

}