using System.IO;
using System.Linq;

namespace MonoGame.FourEngine.Services
{
    public class BasicResourceLoader : IResourceLoader
    {
        public virtual Stream GetStream(string fileName)
        {
            foreach (var assembly in ServiceLocator.Assemblies)
            {
                var names = assembly.GetManifestResourceNames();
                var name = names.FirstOrDefault(n => n.EndsWith(fileName));
                if (name != null)
                {
                    return assembly.GetManifestResourceStream(name);
                }
            }
            throw new FileNotFoundException($"File [{fileName}] not found.");
        }
    }
}