package googleapi

import (
	"net/http"
	"testing"

	"github.com/stretchr/testify/require"
)

func TestHTTPStatusToGoogleStatus(t *testing.T) {
	tests := []struct {
		name   string
		status int
		want   string
	}{
		{"bad_request_400", http.StatusBadRequest, "INVALID_ARGUMENT"},
		{"unauthorized_401", http.StatusUnauthorized, "UNAUTHENTICATED"},
		{"forbidden_403", http.StatusForbidden, "PERMISSION_DENIED"},
		{"not_found_404", http.StatusNotFound, "NOT_FOUND"},
		{"too_many_requests_429", http.StatusTooManyRequests, "RESOURCE_EXHAUSTED"},
		{"internal_server_500", http.StatusInternalServerError, "INTERNAL"},
		{"bad_gateway_502", http.StatusBadGateway, "INTERNAL"},
		{"service_unavailable_503", http.StatusServiceUnavailable, "INTERNAL"},
		{"ok_200", http.StatusOK, "UNKNOWN"},
		{"created_201", http.StatusCreated, "UNKNOWN"},
		{"accepted_202", http.StatusAccepted, "UNKNOWN"},
		{"no_content_204", http.StatusNoContent, "UNKNOWN"},
		{"bad_request_boundary", 400, "INVALID_ARGUMENT"},
		{"server_error_boundary", 500, "INTERNAL"},
		{"custom_4xx", 418, "UNKNOWN"},
		{"custom_5xx", 599, "INTERNAL"},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := HTTPStatusToGoogleStatus(tt.status)
			require.Equal(t, tt.want, got)
		})
	}
}
