package services

// GenerateOTP returns a fresh OTP of the configured length.
//
// It used to `return "123456"` with the real value computed just above it and
// thrown away, and the value it threw away came from math/rand seeded off the
// clock - guessable from the send time. Both are fixed here: the digits come
// from crypto/rand, and the static code is now chosen by NewOTP based on the
// environment rather than being hardcoded into the generator.
//
// Prefer NewOTP, which honours APP_ENV. This is kept for callers that want a
// random value regardless of environment.
func GenerateOTP() string {

	otp, err := generateSecureOTP(ResolveMSG91Config().OTPLength)

	if err != nil {
		return StaticOTPCode()
	}

	return otp
}
