package utils

import (
	"regexp"
	"strconv"
)

var orgIDPatterns = []*regexp.Regexp{
	regexp.MustCompile(`/api/v1/orgs/(?P<org_id>\d+)`),
	regexp.MustCompile(`/api/v1/billing/tenants/(?P<org_id>\d+)`),
	regexp.MustCompile(`/api/v1/unc/tenants/(?P<org_id>\d+)`),
}

func ParseOrgIDFromPath(path string) (uint64, bool) {
	for _, pattern := range orgIDPatterns {
		if index := pattern.SubexpIndex("org_id"); index != -1 {
			res := pattern.FindStringSubmatch(path)
			if res != nil {
				orgID, _ := strconv.ParseUint(res[index], 10, 64)
				return orgID, true
			}
		}
	}
	return 0, false
}
