using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

namespace AssetBank.Settings
{
    public class ComponentWhitelistSettings : ScriptableObject
    {
        private const string k_SettingsPath = "Assets/AssetBank/Assets/ComponentWhitelistSettings.asset";

        [SerializeField]
        private List<string> m_WhitelistedComponents = new();
        public List<string> WhitelistedComponents => m_WhitelistedComponents;

        internal static ComponentWhitelistSettings GetOrCreateSettings()
        {
            var settings = AssetDatabase.LoadAssetAtPath<ComponentWhitelistSettings>(k_SettingsPath);
            if (settings == null)
            {
                settings = CreateInstance<ComponentWhitelistSettings>();
                var directory = Path.GetDirectoryName(k_SettingsPath);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                AssetDatabase.CreateAsset(settings, k_SettingsPath);
                AssetDatabase.SaveAssets();
            }
            return settings;
        }

        internal static SerializedObject GetSerializedSettings()
        {
            return new SerializedObject(GetOrCreateSettings());
        }
    }
}
