package security

import (
	"crypto/rand"
	"encoding/base64"
	"fmt"

	"github.com/btcsuite/btcutil/base58"
)

func GenerateRandomKeyBase64(bytes int) (string, error) {
	if bytes <= 0 {
		return "", fmt.Errorf("key size must be positive")
	}

	key := make([]byte, bytes)
	_, err := rand.Read(key)
	if err != nil {
		return "", fmt.Errorf("failed to generate random key: %w", err)
	}

	return base64.StdEncoding.EncodeToString(key), nil
}

func GenerateRandomKeyBase58(bytes int) (string, error) {
	if bytes <= 0 {
		return "", fmt.Errorf("key size must be positive")
	}

	key := make([]byte, bytes)
	_, err := rand.Read(key)
	if err != nil {
		return "", fmt.Errorf("failed to generate random key: %w", err)
	}

	return base58.Encode(key), nil
}
