package gs.std.v0.core

import java.nio.charset.Charset
import java.nio.charset.StandardCharsets

/** Helper functions for encoding data.
  */
object Encode:

  /** Encode an array of bytes using base64.
    *
    * @param input
    *   The bytes to encode.
    * @return
    *   The base64 string.
    */
  def base64(input: Array[Byte]): B64 = Base64Encoder.encode(input)

  /** Encode a string using base64.
    *
    * @param input
    *   The string to encode.
    * @param charset
    *   The character set of the input string.
    * @return
    *   The base64 string.
    */
  def base64(
    input: String,
    charset: Charset = StandardCharsets.UTF_8
  ): B64 =
    Base64Encoder.encode(input, charset)

  /** Encode an array of bytes using hexadecimal.
    *
    * @param input
    *   The bytes to encode.
    * @return
    *   The hexadecimal string.
    */
  def hex(input: Array[Byte]): Hex = HexEncoder.encode(input)

  /** Encode a string using hexadecimal.
    *
    * @param input
    *   The string to encode.
    * @param charset
    *   The character set of the input string.
    * @return
    *   The hexadecimal string.
    */
  def hex(
    input: String,
    charset: Charset = StandardCharsets.UTF_8
  ): Hex =
    HexEncoder.encode(input, charset)

end Encode
