module Jerimum.PostgreSQL.Types.Jsonb
    -- * CBOR Codec
  ( jsonbEncoderV0
  , jsonbDecoderV0
  , encodeJsonb
    -- * Value constructors
  , fromText
  ) where

import qualified Codec.CBOR.Decoding               as D
import qualified Codec.CBOR.Encoding               as E
import qualified Data.Text                         as T
import           Jerimum.PostgreSQL.Types
import           Jerimum.PostgreSQL.Types.Encoding

v0 :: Version
v0 = 0

encodeJsonb :: Maybe T.Text -> E.Encoding
encodeJsonb = encodeWithVersion v0 jsonbEncoderV0

fromText :: Maybe T.Text -> Value
fromText = mkValue (ScalarType TJsonb) encodeJsonb

jsonbEncoderV0 :: T.Text -> E.Encoding
jsonbEncoderV0 = E.encodeString

jsonbDecoderV0 :: D.Decoder s T.Text
jsonbDecoderV0 = D.decodeString
