package utils

import (
	"regexp"
	"strconv"
)

var orgIDPatterns = []string{
	`/api/v1/orgs/(?P<org_id>\d+)`,
	`/api/userdebug/v1/(?P<org_id>\d+)`,
}

func ParseOrgIDFromPath(path string) (uint64, bool) {
	for _, pattern := range orgIDPatterns {
		re := regexp.MustCompile(pattern)

		if index := re.SubexpIndex("org_id"); index != -1 {
			res := re.FindStringSubmatch(path)
			if res != nil {
				orgID, _ := strconv.ParseUint(res[index], 10, 64)
				return orgID, true
			}
		}
	}
	return 0, false
}
