using System.Reflection;
using System.Text;
using System.Web;
using HeyRed.Mime;

namespace Shoko;

[Protocol("res")]
class ResProtoHandler : ProtoHandler
{
    public ResProtoHandler(Uri url)
    {
        URL = url;
    }

    public override async Task Load()
    {
        var path = HttpUtility.HtmlDecode(URL.AbsolutePath);
        Status = "OK";
        try
        {
            Content = await Download(Assembly.GetExecutingAssembly().GetManifestResourceStream(path));
            MediaType = MimeGuesser.GuessMimeType(Content);
        }
        catch
        {
            Content = new MemoryStream(Encoding.UTF8.GetBytes("resource not found"));
            MediaType = "text/plain";
            Status = "not found";
        }
        OnLoaded();
    }
    public override void Render()
    {
    }
}