syntax = "v1"

type (
	PermissionCatalogQuery {
		Status string `form:"status,optional" validate:"omitempty,oneof=open close"`
		Type   string `form:"type,optional" validate:"omitempty,oneof=backend_user frontend_user"`
		Tree   bool   `form:"tree,optional"`
	}

	PermissionNode {
		ID          string           `json:"id"`
		Parent      string           `json:"parent,omitempty"`
		Name        string           `json:"name"`
		HTTPMethods string           `json:"http_methods,omitempty"`
		HTTPPath    string           `json:"http_path,omitempty"`
		Status      string           `json:"status"`
		Type        string           `json:"type"`
		Children    []PermissionNode `json:"children,omitempty"`
	}

	PermissionCatalogData {
		Tree []PermissionNode `json:"tree,omitempty"`
		List []PermissionNode `json:"list,omitempty"`
	}

	MePermissionsQuery {
		IncludeTree bool `form:"include_tree,optional"`
	}

	MePermissionsData {
		UID         string            `json:"uid"`
		TenantID    string            `json:"tenant_id"`
		Roles       []string          `json:"roles"`
		Permissions map[string]string `json:"permissions"`
		Tree        []PermissionNode  `json:"tree,omitempty"`
	}
)

@server(
	group:      permission
	prefix:     /api/v1/permissions
	middleware: AuthJWT
	tags:       "Permission"
	summary:    "Permission catalog and current member permissions. Requires Bearer JWT."
)
service gateway {
	@handler getPermissionCatalog
	get /catalog (PermissionCatalogQuery) returns (PermissionCatalogData)

	@handler getMePermissions
	get /me (MePermissionsQuery) returns (MePermissionsData)
}
