package httpapi

import (
	"net/http"
	"testing"

	"github.com/easyai/easyai-ai-gateway/apps/api/internal/runner"
)

func TestPricingUnavailableUsesStructuredServiceUnavailableError(t *testing.T) {
	err := &runner.PricingUnavailableError{
		Reason:       "missing, invalid, or not explicitly free",
		ResourceType: "image",
		RuleSetID:    "rule-set-id",
	}
	if got := statusFromRunError(err); got != http.StatusServiceUnavailable {
		t.Fatalf("statusFromRunError()=%d, want %d", got, http.StatusServiceUnavailable)
	}
	if got := runErrorCode(err); got != "pricing_unavailable" {
		t.Fatalf("runErrorCode()=%q, want pricing_unavailable", got)
	}
	details := runErrorDetails(err)
	pricing, _ := details["pricing"].(map[string]any)
	if pricing["resourceType"] != "image" || pricing["ruleSetId"] != "rule-set-id" {
		t.Fatalf("unexpected pricing details: %+v", details)
	}
}
