// WPFMA-SDK needs Unity 2022.3 (VRChat's version); on older Unity this file is skipped and WPFMAUnityVersionNotice explains why.
#if UNITY_2022_3_OR_NEWER
using System;
using System.Collections.Generic;
using System.IO;

namespace WPFMA.Vrca
{
    internal static class WPFMABundleFiles
    {
        internal static readonly string[] Extensions = { ".vrca", ".vrcw", ".vrcb" };

        internal const string PickerFilter = "vrca,vrcw,vrcb";

        internal static bool IsBundle(string path)
        {
            if (string.IsNullOrEmpty(path))
                return false;

            string extension = Path.GetExtension(path);
            foreach (var candidate in Extensions)
            {
                if (string.Equals(extension, candidate, StringComparison.OrdinalIgnoreCase))
                    return true;
            }

            return false;
        }

        internal static List<string> Find(string folder, SearchOption option)
        {
            var found = new List<string>();
            if (string.IsNullOrEmpty(folder) || !Directory.Exists(folder))
                return found;

            foreach (var extension in Extensions)
            {
                try
                {
                    found.AddRange(Directory.GetFiles(folder, "*" + extension, option));
                }
                catch (Exception)
                {
                }
            }

            found.Sort(StringComparer.OrdinalIgnoreCase);
            return found;
        }
    }
}
#endif
