package v1alpha1

import (
	"fmt"
	"strconv"
	"time"
)

func ParseStringToDuration(durationString string) (time.Duration, error) {
	var duration time.Duration
	// If no units are attached, treat as seconds
	if val, err := strconv.Atoi(durationString); err == nil {
		duration = time.Duration(val) * time.Second
	} else if parsed, err := time.ParseDuration(durationString); err == nil {
		duration = parsed
	} else {
		return 0, fmt.Errorf("unable to parse %s as a duration: %w", durationString, err)
	}
	return duration, nil
}
