using System.IO;
using UnityEditor;
using UnityEngine;
using IntelligentProjectAnalyzer.Analyzer;

namespace IntelligentProjectAnalyzer.Editor
{
    public static class AnalyzerSettingsCrud
    {
        private const string SettingsPath = "Assets/IntelligentProjectAnalyzer/Editor/AnalyzerSettings.asset";
        
        public static AnalyzerSettings GetOrCreateSettings()
        {
            var settings = AssetDatabase.LoadAssetAtPath<AnalyzerSettings>(SettingsPath);
            if (settings != null) return settings;
            settings = ScriptableObject.CreateInstance<AnalyzerSettings>();
            var dirName = Path.GetDirectoryName(SettingsPath) ?? "Assets";
            Directory.CreateDirectory(dirName);
            AssetDatabase.CreateAsset(settings, SettingsPath);
            AssetDatabase.SaveAssets();
            return settings;
        }
    }
}