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

using Bayat.SaveSystem.Storage;

namespace Bayat.SaveSystem.PlayMaker
{

    [ActionCategory(SaveSystemAction.ActionCategoryName)]
    [Tooltip("Creates a new backup for the storage item.")]
    public class SaveSystemCreateBackupAction : SaveSystemSettingsAction
    {

        [Tooltip("The unique identifier for this value.")]
        public FsmString identifier;

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

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

    }

    [ActionCategory(SaveSystemAction.ActionCategoryName)]
    [Tooltip("Deletes the backups for the storage item.")]
    public class SaveSystemDeleteBackupsAction : SaveSystemSettingsAction
    {

        [Tooltip("The unique identifier for this value.")]
        public FsmString identifier;

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

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

    }

    [ActionCategory(SaveSystemAction.ActionCategoryName)]
    [Tooltip("Restores the latest backup for the storage item.")]
    public class SaveSystemRestoreLatestBackupAction : SaveSystemSettingsAction
    {

        [Tooltip("The unique identifier for this value.")]
        public FsmString identifier;

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

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

    }

}