package common

import (
	"errors"
	"fmt"
	"regexp"
	"strconv"
)

var resourcePoolIDRegexp = regexp.MustCompile(`^\d+$`)

func ParseResourcePoolID(resourcePoolID string) (uint64, error) {
	if !resourcePoolIDRegexp.MatchString(resourcePoolID) {
		return 0, errors.New("resource pool id must be an unsigned decimal integer")
	}

	id, err := strconv.ParseUint(resourcePoolID, 10, 64)
	if err != nil {
		return 0, fmt.Errorf("parse resource pool id: %w", err)
	}
	if id == 0 {
		return 0, errors.New("resource pool id must be greater than zero")
	}
	return id, nil
}

func ResourcePoolName(resourcePoolID uint64) string {
	return fmt.Sprintf("resourcePools/%d", resourcePoolID)
}
