using Dalamud.Bindings.ImGui;
using Dalamud.Plugin.SelfTest;
using HellionChat.Branding;

namespace HellionChat.SelfTests;

// Verifies the embedded fox-banner PNG decodes into a usable texture. The load
// is async, so the step returns Waiting until Dalamud finishes the decode and
// the self-test runner re-polls. A decode or resource error is a build defect
// and fails the step hard. The resource lives in the DLL, it cannot be a
// runtime miss.
internal sealed class FoxBannerTextureSmokeStep : ISelfTestStep
{
    private readonly Plugin plugin;

    public FoxBannerTextureSmokeStep(Plugin plugin)
    {
        this.plugin = plugin;
    }

    public string Name => "Hellion Chat - Fox banner texture smoke";

    public SelfTestStepResult RunStep()
    {
        if (!FoxBannerTexture.Shared.TryGetWrap(out var wrap, out var ex))
        {
            if (ex is not null)
            {
                ImGui.Text($"Fox banner load failed: {ex.Message}");
                return SelfTestStepResult.Fail;
            }

            ImGui.Text("Fox banner still loading...");
            return SelfTestStepResult.Waiting;
        }

        if (wrap.Size.X <= 0 || wrap.Size.Y <= 0)
        {
            ImGui.Text($"Fox banner has degenerate size {wrap.Size}");
            return SelfTestStepResult.Fail;
        }

        return SelfTestStepResult.Pass;
    }

    public void CleanUp() { }
}
