module Jerimum.PostgreSQL.Types.Boolean
    -- * CBOR codec
  ( boolEncoderV0
  , boolDecoderV0
  , encodeBool
    -- * Value constructors
  , fromBool
  ) where

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

v0 :: Version
v0 = 0

encodeBool :: Maybe Bool -> E.Encoding
encodeBool = encodeWithVersion v0 boolEncoderV0

boolEncoderV0 :: Bool -> E.Encoding
boolEncoderV0 = E.encodeBool

boolDecoderV0 :: D.Decoder s Bool
boolDecoderV0 = D.decodeBool

fromBool :: Maybe Bool -> Value
fromBool = mkValue (ScalarType TBoolean) encodeBool
