package interceptor

// var pathPatternResourceMap = map[string]string{
// 	"/api/v1/external.*/orgs/(.+)/projects/(.+)/clusters/(.+)/monitor-alertrules": "o11y/orgs/{org_id}/projects/{project_id}/clusters/{cluster_id}/monitor-alertrules",
// 	"/api/v1/external.*/orgs/(.+)/projects/(.+)/clusters/(.+)/alerts":             "o11y/orgs/{org_id}/projects/{project_id}/clusters/{cluster_id}/alerts",
// }

// var pathWhitelist = []string{}

//
//func UseAdapter(c *gin.Context) {
//	bizType := c.Param("bizType")
//	checker, err := getPermissionChecker(bizType)
//	if err != nil {
//		log.Errorf("getPermissionChecker failed: %v", err)
//		authError(c, "Unauthorized")
//		return
//	}
//	result, err := checker.Handle(c.Request.Context(), useadapter.GenAccessParam4Gin(c))
//	if !useadapter.DefaultAccessDecideCompleteExecFunc(c.Writer, c.Request, result, err) {
//		c.Abort()
//		return
//	}
//	c.Next()
//}

// nasty hack as tiinf do not support a multi-env permissionHelper for now.
// o11yPermissionHelper is a custom implementation of common.PermissionHelper
// type o11yPermissionHelper struct {
// 	cli         account.AccountAPIServiceClient
// 	readTimeout time.Duration
// }

// func (h *o11yPermissionHelper) HasPermission(ctx context.Context, identity, resource string) (bool, error) {
// 	identInt, err := strconv.ParseUint(identity, 10, 64)
// 	if err != nil {
// 		return false, fmt.Errorf("defaultPermissionHelper: %s", err.Error())
// 	}
// 	req := account.RbacPermissionRequest{
// 		UserId:      identInt,
// 		ResourceUri: resource,
// 	}

// 	timeout := h.readTimeout
// 	if timeout == 0 {
// 		timeout = 6 * time.Second
// 	}
// 	tctx, cf := context.WithTimeout(ctx, timeout)
// 	defer cf()

// 	rsp, err := h.cli.HasPermissionForUser(tctx, &req)
// 	if err != nil {
// 		return false, fmt.Errorf("defaultPermissionHelper: %s", err.Error())
// 	}
// 	return rsp.AuthResult, nil
// }
