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

namespace AssetBank.Settings
{
    public enum UnityAssetType
    {
        Animation,
        AnimatorController,
        AnimatorOverrideController,
        AudioClip,
        AudioMixer,
        ComputeShader,
        Font,
        GUISkin,
        Material,
        Mesh,
        Model,
        PhysicMaterial,
        Prefab,
        Scene,
        Script,
        Shader,
        Sprite,
        Texture,
        VideoClip,
        RenderTexture,
        LightmapParameters,
        Custom
    }

    [System.Serializable]
    public class IgnoredUnityType
    {
        public UnityAssetType assetType = UnityAssetType.Texture;
        public string customType = "";
    }

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

        [SerializeField]
        private List<string> m_FoldersToIgnore = new();
        public List<string> FoldersToIgnore => m_FoldersToIgnore;

        [SerializeField]
        private List<string> m_FileExtensionsToIgnore = new();
        public List<string> FileExtensionsToIgnore => m_FileExtensionsToIgnore;

        [SerializeField]
        private List<IgnoredUnityType> m_UnityTypesToIgnore = new();
        public List<IgnoredUnityType> UnityTypesToIgnore => m_UnityTypesToIgnore;


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