/*
<copyright file="BGGCFileBasedA.cs" company="BansheeGz">
    Copyright (c) 2018-2022 All Rights Reserved
</copyright>
*/


using System;
using System.IO;
using GameCreator.Runtime.Common;
using UnityEngine;

namespace BansheeGz.BGDatabase
{
    /// <summary>
    /// Action, based on the file in persistent folder
    /// </summary>
    [Serializable]
    public abstract class BGGCFileBasedA : BGGCAction
    {
        [SerializeField] private PropertyGetString fileName = GetStringString.Create;

        protected abstract string FileExt { get; }
        
        public string GetPath(Args args)
        {
            var realFileName = fileName.Get(args);

            if (string.IsNullOrEmpty(realFileName)) return null;

            var path = Path.Combine(Application.persistentDataPath, realFileName);
            if (FileExt != null) path = Path.ChangeExtension(path, FileExt);
            return path;
        }
    }
}