using RebootKit.Engine.Foundation;
using UnityEngine;

namespace RebootKit.Engine.Services.Console {
    [CreateAssetMenu(menuName = RConsts.ServiceAssetMenu + "Console")]
    public class ConsoleServiceAsset : ServiceAsset<ConsoleService> {
        [SerializeField]
        private ConsoleService.Config _config;

        [SerializeField]
        private CVar[] _initialCVars;

        [SerializeField]
        private bool _loadCVarsFromResources = true;

        public override ConsoleService Create() {
            ConsoleService service = new(_config);
            foreach (CVar cvar in _initialCVars) {
                service.Replace(cvar);
                cvar.Reset();
            }

            if (_loadCVarsFromResources) {
                CVarAsset[] cvarsAssets = Resources.LoadAll<CVarAsset>("cvar");
                foreach (CVarAsset cvarAsset in cvarsAssets) {
                    CVar cvar = cvarAsset.Create();
                    service.Replace(cvar);
                }
            }

            return new ConsoleService(_config);
        }
    }
}