package serverruntime

import (
	"context"
	"net/http"
	"reflect"
	"strings"
	"testing"

	"github.com/gin-gonic/gin"
	sharedialect "github.com/nexuscrm/shared/pkg/dialect"
)

func TestComposeProductDistributionMergesRuntimeRouteSurfaces(t *testing.T) {
	gin.SetMode(gin.TestMode)

	hooks, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"alpha-pack"},
			Capabilities: ProductCapabilities{
				RuntimeRouteSurfaces: []RuntimeRouteSurfaceRegistration{
					{
						Name:     "Alpha-Surface",
						Register: testRuntimeRouteSurface("/alpha-surface", "alpha"),
					},
				},
			},
		},
		ProductHooks{
			OwningAppPacks: []string{"beta-pack"},
			Capabilities: ProductCapabilities{
				RuntimeRouteSurfaces: []RuntimeRouteSurfaceRegistration{
					{
						Name:     "beta-surface",
						Register: testRuntimeRouteSurface("/beta-surface", "beta"),
					},
				},
			},
		},
	))
	if err != nil {
		t.Fatalf("ComposeProductDistribution: %v", err)
	}

	if got, want := runtimeRouteSurfaceNames(hooks.Capabilities.RuntimeRouteSurfaces), []string{"alpha-surface", "beta-surface"}; !reflect.DeepEqual(got, want) {
		t.Fatalf("RuntimeRouteSurfaces names = %#v, want %#v", got, want)
	}

}

func TestComposeProductDistributionRejectsRuntimeRouteSurfaceWithoutRegisterFunction(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				RuntimeRouteSurfaces: []RuntimeRouteSurfaceRegistration{{Name: "missing-register"}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want missing runtime route surface register function")
	}
	if got := err.Error(); !strings.Contains(got, "missing-register") || !strings.Contains(got, "requires register function") {
		t.Fatalf("error = %q, want missing runtime route surface register details", got)
	}
}

func TestComposeProductDistributionRejectsDialectRouteReplacementWithoutHandler(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				RuntimeRouteSurfaces: []RuntimeRouteSurfaceRegistration{{
					Name: "folder-surface",
					ReplacesDialectRoutes: []DialectRouteReplacement{
						{DialectName: "test-dialect", Method: http.MethodPost, Path: "/folders"},
					},
				}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want missing replacement handler error")
	}
	if got := err.Error(); !strings.Contains(got, "folder-surface") || !strings.Contains(got, "requires handler") {
		t.Fatalf("error = %q, want missing replacement handler details", got)
	}
}

func TestComposeProductDistributionRejectsRuntimeRouteSurfaceMixingRegisterAndReplacement(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				RuntimeRouteSurfaces: []RuntimeRouteSurfaceRegistration{{
					Name:     "folder-surface",
					Register: noopRuntimeRouteSurface,
					ReplacesDialectRoutes: []DialectRouteReplacement{
						{DialectName: "test-dialect", Method: http.MethodPost, Path: "/folders", Handler: testDialectReplacementHandler("replacement")},
					},
				}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want mixed register/replacement error")
	}
	if got := err.Error(); !strings.Contains(got, "folder-surface") || !strings.Contains(got, "cannot mix register function with dialect route replacements") {
		t.Fatalf("error = %q, want mixed register/replacement details", got)
	}
}

func TestComposeProductDistributionRejectsDuplicateRuntimeRouteSurface(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"alpha-pack"},
			Capabilities: ProductCapabilities{
				RuntimeRouteSurfaces: []RuntimeRouteSurfaceRegistration{{Name: "shared-surface", Register: noopRuntimeRouteSurface}},
			},
		},
		ProductHooks{
			OwningAppPacks: []string{"beta-pack"},
			Capabilities: ProductCapabilities{
				RuntimeRouteSurfaces: []RuntimeRouteSurfaceRegistration{{Name: "Shared-Surface", Register: noopRuntimeRouteSurface}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want duplicate runtime route surface conflict")
	}
	if got := err.Error(); !strings.Contains(got, "product[1]") || !strings.Contains(got, "runtime route surface") || !strings.Contains(got, "product[0]") {
		t.Fatalf("error = %q, want duplicate runtime route surface with product indexes", got)
	}
}

func TestComposeProductDistributionRejectsRuntimeRouteSurfaceWithoutOwningPack(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			Capabilities: ProductCapabilities{
				RuntimeRouteSurfaces: []RuntimeRouteSurfaceRegistration{{Name: "test-surface", Register: noopRuntimeRouteSurface}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want runtime route surface owner-pack error")
	}
	if got := err.Error(); !strings.Contains(got, "runtime route surface") || !strings.Contains(got, "requires owning app pack") {
		t.Fatalf("error = %q, want runtime route surface owner-pack details", got)
	}
}

func TestComposeProductDistributionRejectsDynamicCORSRouteFamilyWithoutPredicate(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				DynamicCORSRouteFamilies: []DynamicCORSRouteFamilyRegistration{{Name: "missing-predicate"}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want missing dynamic CORS route predicate")
	}
	if got := err.Error(); !strings.Contains(got, "missing-predicate") || !strings.Contains(got, "requires route predicate") {
		t.Fatalf("error = %q, want missing dynamic CORS route predicate details", got)
	}
}

func TestComposeProductDistributionRejectsDuplicateDynamicCORSRouteFamily(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"alpha-pack"},
			Capabilities: ProductCapabilities{
				DynamicCORSRouteFamilies: []DynamicCORSRouteFamilyRegistration{{Name: "shared-cors", Allows: testDynamicCORSRouteFamily}},
			},
		},
		ProductHooks{
			OwningAppPacks: []string{"beta-pack"},
			Capabilities: ProductCapabilities{
				DynamicCORSRouteFamilies: []DynamicCORSRouteFamilyRegistration{{Name: "Shared-CORS", Allows: testDynamicCORSRouteFamily}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want duplicate dynamic CORS route family conflict")
	}
	if got := err.Error(); !strings.Contains(got, "product[1]") || !strings.Contains(got, "dynamic CORS route family") || !strings.Contains(got, "product[0]") {
		t.Fatalf("error = %q, want duplicate dynamic CORS route family with product indexes", got)
	}
}

func TestComposeProductDistributionRejectsDynamicCORSRouteFamilyWithoutOwningPack(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			Capabilities: ProductCapabilities{
				DynamicCORSRouteFamilies: []DynamicCORSRouteFamilyRegistration{{Name: "test-cors", Allows: testDynamicCORSRouteFamily}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want dynamic CORS route family owner-pack error")
	}
	if got := err.Error(); !strings.Contains(got, "dynamic CORS route family") || !strings.Contains(got, "requires owning app pack") {
		t.Fatalf("error = %q, want dynamic CORS route family owner-pack details", got)
	}
}

func TestComposeProductDistributionRejectsDynamicCORSRouteFamilyWithoutName(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				DynamicCORSRouteFamilies: []DynamicCORSRouteFamilyRegistration{{Allows: testDynamicCORSRouteFamily}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want dynamic CORS route family name error")
	}
	if got := err.Error(); !strings.Contains(got, "dynamic CORS route family") || !strings.Contains(got, "requires name") {
		t.Fatalf("error = %q, want dynamic CORS route family name details", got)
	}
}

func TestComposeProductDistributionRejectsOAuthScopeRouteFamilyWithoutPredicate(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				OAuthScopeRouteFamilies: []OAuthScopeRouteFamilyRegistration{{Name: "missing-predicate", Scopes: []string{"openid"}}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want missing OAuth scope route predicate")
	}
	if got := err.Error(); !strings.Contains(got, "missing-predicate") || !strings.Contains(got, "requires route predicate") {
		t.Fatalf("error = %q, want missing OAuth scope route predicate details", got)
	}
}

func TestComposeProductDistributionRejectsOAuthScopeRouteFamilyForPlatformBroadScope(t *testing.T) {
	for _, scope := range []string{"api", "full", "api.read"} {
		t.Run(scope, func(t *testing.T) {
			_, err := ComposeProductDistribution(NewProductDistribution(
				ProductHooks{
					OwningAppPacks: []string{"test-pack"},
					Capabilities: ProductCapabilities{
						OAuthScopeRouteFamilies: []OAuthScopeRouteFamilyRegistration{{Name: "platform-read", Scopes: []string{scope}, Allows: testOAuthScopeRouteFamily}},
					},
				},
			))
			if err == nil {
				t.Fatal("ComposeProductDistribution succeeded; want platform broad OAuth scope error")
			}
			if got := err.Error(); !strings.Contains(got, "platform-read") || !strings.Contains(got, "must not claim platform broad OAuth scope") {
				t.Fatalf("error = %q, want platform broad OAuth scope details", got)
			}
		})
	}
}

func TestComposeProductDistributionRejectsOAuthScopeRouteFamilyForCustomScope(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				OAuthScopeRouteFamilies: []OAuthScopeRouteFamilyRegistration{{Name: "custom-route", Scopes: []string{"product.notifications"}, Allows: testOAuthScopeRouteFamily}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want custom OAuth scope route family error")
	}
	if got := err.Error(); !strings.Contains(got, "custom-route") || !strings.Contains(got, "uses undeclared product OAuth route scope") || !strings.Contains(got, "custom scopes must be backed by _System_OAuthCustomScope") {
		t.Fatalf("error = %q, want custom scope metadata-backed details", got)
	}
}

func TestComposeProductDistributionAcceptsSourceBackedOAuthScopeRouteFamily(t *testing.T) {
	hooks, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				OAuthScopeRouteFamilies: []OAuthScopeRouteFamilyRegistration{{
					Name:                     "source-backed-route",
					Scopes:                   []string{" External.Records.Read "},
					Allows:                   testOAuthScopeRouteFamily,
					RequireActiveSourceScope: true,
				}},
			},
		},
	))
	if err != nil {
		t.Fatalf("ComposeProductDistribution returned error: %v", err)
	}
	if len(hooks.Capabilities.OAuthRouteScopes) != 0 {
		t.Fatalf("OAuthRouteScopes = %#v, want source-backed scope to remain metadata-owned", hooks.Capabilities.OAuthRouteScopes)
	}
	if got, want := hooks.Capabilities.OAuthScopeRouteFamilies[0].Scopes, []string{"external.records.read"}; !reflect.DeepEqual(got, want) {
		t.Fatalf("OAuthScopeRouteFamilies[0].Scopes = %#v, want canonical source-backed scope %#v", got, want)
	}
	if !hooks.Capabilities.OAuthScopeRouteFamilies[0].RequireActiveSourceScope {
		t.Fatal("source-backed OAuth scope route family lost active-source gate")
	}
}

func TestComposeProductDistributionRejectsSourceBackedOAuthScopeDeclaredAsProductScope(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				OAuthRouteScopes: []OAuthRouteScopeRegistration{{Scope: "external.records.read"}},
				OAuthScopeRouteFamilies: []OAuthScopeRouteFamilyRegistration{{
					Name:                     "source-backed-route",
					Scopes:                   []string{"external.records.read"},
					Allows:                   testOAuthScopeRouteFamily,
					RequireActiveSourceScope: true,
				}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want conflicting source-backed/product scope classification error")
	}
	if got := err.Error(); !strings.Contains(got, "source-backed-route") || !strings.Contains(got, "source-backed") || !strings.Contains(got, "OAuthRouteScopes") {
		t.Fatalf("error = %q, want source-backed/product scope classification details", got)
	}
}

func TestComposeProductDistributionAcceptsDeclaredVendorOAuthRouteScope(t *testing.T) {
	hooks, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				OAuthRouteScopes:        []OAuthRouteScopeRegistration{{Scope: " Vendor.Builtin "}},
				OAuthScopeRouteFamilies: []OAuthScopeRouteFamilyRegistration{{Name: "vendor-route", Scopes: []string{"vendor.builtin"}, Allows: testOAuthScopeRouteFamily}},
			},
		},
	))
	if err != nil {
		t.Fatalf("ComposeProductDistribution returned error: %v", err)
	}
	if got, want := hooks.Capabilities.OAuthRouteScopes, []OAuthRouteScopeRegistration{{Scope: "vendor.builtin", owningAppPacks: []string{"test-pack"}}}; !reflect.DeepEqual(got, want) {
		t.Fatalf("OAuthRouteScopes = %#v, want %#v", got, want)
	}
	if got, want := hooks.Capabilities.OAuthScopeRouteFamilies[0].Scopes, []string{"vendor.builtin"}; !reflect.DeepEqual(got, want) {
		t.Fatalf("OAuthScopeRouteFamilies[0].Scopes = %#v, want canonical scopes %#v", got, want)
	}
}

func TestComposeProductDistributionRejectsDuplicateProductOAuthRouteScope(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"alpha-pack"},
			Capabilities: ProductCapabilities{
				OAuthRouteScopes: []OAuthRouteScopeRegistration{{Scope: "vendor.builtin"}},
			},
		},
		ProductHooks{
			OwningAppPacks: []string{"beta-pack"},
			Capabilities: ProductCapabilities{
				OAuthRouteScopes: []OAuthRouteScopeRegistration{{Scope: "Vendor.Builtin"}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want duplicate OAuth route scope error")
	}
	if got := err.Error(); !strings.Contains(got, "OAuth route scope") || !strings.Contains(got, "duplicates product[0]") {
		t.Fatalf("error = %q, want duplicate OAuth route scope details", got)
	}
}

func TestComposeProductDistributionRejectsDuplicateOAuthScopeRouteFamily(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"alpha-pack"},
			Capabilities: ProductCapabilities{
				OAuthScopeRouteFamilies: []OAuthScopeRouteFamilyRegistration{{Name: "shared-scope-route", Scopes: []string{"openid"}, Allows: testOAuthScopeRouteFamily}},
			},
		},
		ProductHooks{
			OwningAppPacks: []string{"beta-pack"},
			Capabilities: ProductCapabilities{
				OAuthScopeRouteFamilies: []OAuthScopeRouteFamilyRegistration{{Name: "Shared-Scope-Route", Scopes: []string{"openid"}, Allows: testOAuthScopeRouteFamily}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want duplicate OAuth scope route family conflict")
	}
	if got := err.Error(); !strings.Contains(got, "product[1]") || !strings.Contains(got, "OAuth scope route family") || !strings.Contains(got, "product[0]") {
		t.Fatalf("error = %q, want duplicate OAuth scope route family with product indexes", got)
	}
}

func TestComposeProductDistributionRejectsOAuthScopeRouteFamilyWithoutOwningPack(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			Capabilities: ProductCapabilities{
				OAuthScopeRouteFamilies: []OAuthScopeRouteFamilyRegistration{{Name: "test-scope-route", Scopes: []string{"openid"}, Allows: testOAuthScopeRouteFamily}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want OAuth scope route family owner-pack error")
	}
	if got := err.Error(); !strings.Contains(got, "OAuth scope route family") || !strings.Contains(got, "requires owning app pack") {
		t.Fatalf("error = %q, want OAuth scope route family owner-pack details", got)
	}
}

func TestComposeProductDistributionRejectsOAuthScopeRouteFamilyWithoutName(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				OAuthScopeRouteFamilies: []OAuthScopeRouteFamilyRegistration{{Scopes: []string{"openid"}, Allows: testOAuthScopeRouteFamily}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want OAuth scope route family name error")
	}
	if got := err.Error(); !strings.Contains(got, "OAuth scope route family") || !strings.Contains(got, "requires name") {
		t.Fatalf("error = %q, want OAuth scope route family name details", got)
	}
}

func TestComposeProductDistributionRejectsOAuthScopeRouteFamilyWithoutScope(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				OAuthScopeRouteFamilies: []OAuthScopeRouteFamilyRegistration{{Name: "test-scope-route", Allows: testOAuthScopeRouteFamily}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want OAuth scope route family scope error")
	}
	if got := err.Error(); !strings.Contains(got, "OAuth scope route family") || !strings.Contains(got, "requires at least one scope") {
		t.Fatalf("error = %q, want OAuth scope route family scope details", got)
	}
}

func TestComposeProductDistributionRejectsAuthChallengeProfileWithoutBuilder(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				AuthChallengeProfiles: []AuthChallengeProfileRegistration{{ProfileID: "missing-builder"}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want missing auth challenge builder")
	}
	if got := err.Error(); !strings.Contains(got, "missing-builder") || !strings.Contains(got, "requires builder") {
		t.Fatalf("error = %q, want missing auth challenge builder details", got)
	}
}

func TestComposeProductDistributionRejectsDuplicateAuthChallengeProfile(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"alpha-pack"},
			Capabilities: ProductCapabilities{
				AuthChallengeProfiles: []AuthChallengeProfileRegistration{{ProfileID: "shared-challenge", Build: testAuthChallengeProfile}},
			},
		},
		ProductHooks{
			OwningAppPacks: []string{"beta-pack"},
			Capabilities: ProductCapabilities{
				AuthChallengeProfiles: []AuthChallengeProfileRegistration{{ProfileID: "Shared-Challenge", Build: testAuthChallengeProfile}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want duplicate auth challenge profile conflict")
	}
	if got := err.Error(); !strings.Contains(got, "product[1]") || !strings.Contains(got, "auth challenge profile") || !strings.Contains(got, "product[0]") {
		t.Fatalf("error = %q, want duplicate auth challenge profile with product indexes", got)
	}
}

func TestComposeProductDistributionRejectsAuthChallengeProfileWithoutOwningPack(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			Capabilities: ProductCapabilities{
				AuthChallengeProfiles: []AuthChallengeProfileRegistration{{ProfileID: "test-challenge", Build: testAuthChallengeProfile}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want auth challenge profile owner-pack error")
	}
	if got := err.Error(); !strings.Contains(got, "auth challenge profile") || !strings.Contains(got, "requires owning app pack") {
		t.Fatalf("error = %q, want auth challenge profile owner-pack details", got)
	}
}

func TestComposeProductDistributionRejectsAuthChallengeProfileWithoutID(t *testing.T) {
	_, err := ComposeProductDistribution(NewProductDistribution(
		ProductHooks{
			OwningAppPacks: []string{"test-pack"},
			Capabilities: ProductCapabilities{
				AuthChallengeProfiles: []AuthChallengeProfileRegistration{{Build: testAuthChallengeProfile}},
			},
		},
	))
	if err == nil {
		t.Fatal("ComposeProductDistribution succeeded; want auth challenge profile id error")
	}
	if got := err.Error(); !strings.Contains(got, "auth challenge profile") || !strings.Contains(got, "requires id") {
		t.Fatalf("error = %q, want auth challenge profile id details", got)
	}
}

func runtimeRouteSurfaceNames(surfaces []RuntimeRouteSurfaceRegistration) []string {
	names := make([]string, 0, len(surfaces))
	for _, surface := range surfaces {
		names = append(names, surface.Name)
	}
	return names
}

func testRuntimeRouteSurface(path, body string) func(RuntimeRouteSurfaceContext) error {
	return func(ctx RuntimeRouteSurfaceContext) error {
		ctx.Router.GET(path, func(c *gin.Context) { c.String(http.StatusOK, body) })
		return nil
	}
}

func noopRuntimeRouteSurface(RuntimeRouteSurfaceContext) error {
	return nil
}

func testDialectReplacementHandler(source string) sharedialect.Handler {
	return func(context.Context, *sharedialect.Request, sharedialect.Deps) (*sharedialect.Response, error) {
		return &sharedialect.Response{Status: http.StatusOK, Body: gin.H{"source": source}}, nil
	}
}

func testDynamicCORSRouteFamily(DynamicCORSRouteContext) bool {
	return true
}

func testOAuthScopeRouteFamily(OAuthScopeRouteContext) bool {
	return true
}

func testAuthChallengeProfile(AuthChallengeContext) (AuthChallenge, bool) {
	return AuthChallenge{Status: http.StatusForbidden, Code: "test", Message: "test"}, true
}
