using System.IO;
using Bolt;
using Ludiq;
using UnityEngine;

namespace BansheeGz.BGDatabase
{
    /// <summary>
    /// Abstract action for all SaveLoad related actions which has filename as a parameter
    /// </summary>
    public abstract partial class SaveLoadWithNameA : SaveLoadA
    {
        private const string DefaultFileName = "game";

        [DoNotSerialize] public ControlInput _in;
        [DoNotSerialize] public ControlOutput _out;

        [DoNotSerialize] public ValueInput fileName;

        protected string FullFileName(Flow flow)
        {
            var name = flow.GetValue<string>(fileName);
            if (string.IsNullOrEmpty(name)) name = DefaultFileName;
            return Path.ChangeExtension(Path.Combine(Application.persistentDataPath, name), "." + FileExt);
        }

        protected override void Definition()
        {
            _in = ControlInput("_in", Enter);
            _out = ControlOutput("_out");
            Succession(_in, _out);

            base.Definition();
            fileName = ValueInput("File Name", "");
        }

        protected abstract ControlOutput Enter(Flow flow);
    }
}