using System.Collections.Generic;
using System.IO;
using AssetBank.Editor.Tools;
using UnityEditor;
using UnityEngine;

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

        [SerializeField]
        private List<ComponentStats> m_ComponentStats = new();
        public List<ComponentStats> ComponentStats => m_ComponentStats;
        
        [SerializeField]
        private string m_LastScanTime;
        public string LastScanTime
        {
            get => m_LastScanTime;
            set => m_LastScanTime = value;
        }

        internal static ComponentStatsSettings GetOrCreateSettings()
        {
            var settings = AssetDatabase.LoadAssetAtPath<ComponentStatsSettings>(k_SettingsPath);
            if (settings == null)
            {
                settings = CreateInstance<ComponentStatsSettings>();
                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());
        }
    }
}
