﻿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("Copies the storage item to new location or replaces the existing storage item.")]
    public class SaveSystemCopyAction : SaveSystemSettingsAction
    {

        [Tooltip("The unique identifier for the source storage item.")]
        public FsmString fromIdentifier;
        [Tooltip("The unique identifier for the destination storage item or location.")]
        public FsmString toIdentifier;
        [Tooltip("Replace the destination storage item if exists.")]
        public FsmBool replace;

        public override void OnReset()
        {
            this.fromIdentifier = "hello-world";
            this.toIdentifier = "new/hello-world";
            this.replace = true;
        }

        public override void Enter()
        {
            if (this.settingsPreset)
            {
                SaveSystemAPI.CopyAsync(this.fromIdentifier.Value, this.toIdentifier.Value, this.replace.Value, this.settingsPreset.CustomSettings).ContinueWith(HandleTask);
            }
            else
            {

                SaveSystemAPI.CopyAsync(this.fromIdentifier.Value, this.toIdentifier.Value, this.replace.Value).ContinueWith(HandleTask);
            }
        }

    }

}