{-# LANGUAGE DataKinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

-- | Defines /Base64/ encoding for Text
-- This version has poor performance.
--
-- @since 0.5.0.0
module Data.TypedEncoding.Instances.Enc.Warn.Base64 {-# WARNING "Not optimized for performance" #-} where

import           Data.TypedEncoding
import           Data.TypedEncoding.Instances.Support

import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Encoding as TE 
import qualified Data.Text.Lazy.Encoding as TEL 

import qualified Data.ByteString.Base64 as B64
import qualified Data.ByteString.Base64.Lazy as BL64

-- | This instance will likely be removed in future versions (performance concerns)
-- (Moved from "Data.TypedEncoding.Instances.Enc.Base64")

-- @since 0.3.0.0
instance Applicative f => Encode f "enc-B64" "enc-B64" c T.Text where
    encoding :: Encoding f "enc-B64" "enc-B64" c Text
encoding = Encoding f "enc-B64" "enc-B64" c Text
forall (f :: * -> *) c.
Applicative f =>
Encoding f "enc-B64" "enc-B64" c Text
endB64T

-- | This function will likely be removed in future versions (performance concerns)
-- (Moved from "Data.TypedEncoding.Instances.Enc.Base64")
--
-- @since 0.3.0.0
endB64T :: Applicative f => Encoding f "enc-B64" "enc-B64" c T.Text
endB64T :: Encoding f "enc-B64" "enc-B64" c Text
endB64T = (Text -> Text) -> Encoding f "enc-B64" (AlgNm "enc-B64") c Text
forall (nm :: Symbol) (f :: * -> *) c str.
Applicative f =>
(str -> str) -> Encoding f nm (AlgNm nm) c str
_implEncodingP (ByteString -> Text
TE.decodeUtf8 (ByteString -> Text) -> (Text -> ByteString) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
B64.encode (ByteString -> ByteString)
-> (Text -> ByteString) -> Text -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TE.encodeUtf8)  


-- | 
--
-- @since 0.3.0.0
instance (UnexpectedDecodeErr f, Applicative f) => Decode f "enc-B64" "enc-B64" c T.Text where
    decoding :: Decoding f "enc-B64" "enc-B64" c Text
decoding = Decoding f "enc-B64" "enc-B64" c Text
forall (f :: * -> *) c.
(UnexpectedDecodeErr @* f, Applicative f) =>
Decoding f "enc-B64" "enc-B64" c Text
decB64T

-- |
-- @since 0.3.0.0 
decB64T :: (UnexpectedDecodeErr f, Applicative f) => Decoding f "enc-B64" "enc-B64" c T.Text
decB64T :: Decoding f "enc-B64" "enc-B64" c Text
decB64T = (Text -> f Text) -> Decoding f "enc-B64" (AlgNm "enc-B64") c Text
forall (nm :: Symbol) (f :: * -> *) c str.
Functor f =>
(str -> f str) -> Decoding f nm (AlgNm nm) c str
_implDecodingF (forall (x :: Symbol) (f :: * -> *) err a.
(KnownSymbol x, UnexpectedDecodeErr @* f, Applicative f,
 Show err) =>
Either err a -> f a
forall (f :: * -> *) err a.
(KnownSymbol "enc-B64", UnexpectedDecodeErr @* f, Applicative f,
 Show err) =>
Either err a -> f a
asUnexpected @"enc-B64"  (Either String Text -> f Text)
-> (Text -> Either String Text) -> Text -> f Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> Text)
-> Either String ByteString -> Either String Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Text
TE.decodeUtf8 (Either String ByteString -> Either String Text)
-> (Text -> Either String ByteString) -> Text -> Either String Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either String ByteString
B64.decode (ByteString -> Either String ByteString)
-> (Text -> ByteString) -> Text -> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TE.encodeUtf8) 

-- | 
--
-- @since 0.3.0.0 
instance (UnexpectedDecodeErr f, Applicative f) => Decode f "enc-B64" "enc-B64" c TL.Text where
    decoding :: Decoding f "enc-B64" "enc-B64" c Text
decoding = Decoding f "enc-B64" "enc-B64" c Text
forall (f :: * -> *) c.
(UnexpectedDecodeErr @* f, Applicative f) =>
Decoding f "enc-B64" "enc-B64" c Text
decB64TL

-- |
-- @since 0.3.0.0 
decB64TL :: (UnexpectedDecodeErr f, Applicative f) => Decoding f "enc-B64" "enc-B64" c TL.Text
decB64TL :: Decoding f "enc-B64" "enc-B64" c Text
decB64TL = (Text -> f Text) -> Decoding f "enc-B64" (AlgNm "enc-B64") c Text
forall (nm :: Symbol) (f :: * -> *) c str.
Functor f =>
(str -> f str) -> Decoding f nm (AlgNm nm) c str
_implDecodingF (forall (x :: Symbol) (f :: * -> *) err a.
(KnownSymbol x, UnexpectedDecodeErr @* f, Applicative f,
 Show err) =>
Either err a -> f a
forall (f :: * -> *) err a.
(KnownSymbol "enc-B64", UnexpectedDecodeErr @* f, Applicative f,
 Show err) =>
Either err a -> f a
asUnexpected @"enc-B64"  (Either String Text -> f Text)
-> (Text -> Either String Text) -> Text -> f Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> Text)
-> Either String ByteString -> Either String Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Text
TEL.decodeUtf8 (Either String ByteString -> Either String Text)
-> (Text -> Either String ByteString) -> Text -> Either String Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either String ByteString
BL64.decode (ByteString -> Either String ByteString)
-> (Text -> ByteString) -> Text -> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TEL.encodeUtf8) 

-- |
-- @since 0.3.0.0 
instance (RecreateErr f, Applicative f) => Validate f "enc-B64" "enc-B64" c T.Text where
    validation :: Validation f "enc-B64" "enc-B64" c Text
validation = Decoding (Either UnexpectedDecodeEx) "enc-B64" "enc-B64" c Text
-> Validation f "enc-B64" "enc-B64" c Text
forall (nm :: Symbol) (f :: * -> *) c str.
(KnownSymbol nm, RecreateErr @* f, Applicative f) =>
Decoding (Either UnexpectedDecodeEx) nm nm c str
-> Validation f nm nm c str
validFromDec Decoding (Either UnexpectedDecodeEx) "enc-B64" "enc-B64" c Text
forall (f :: * -> *) c.
(UnexpectedDecodeErr @* f, Applicative f) =>
Decoding f "enc-B64" "enc-B64" c Text
decB64T

-- |
-- @since 0.3.0.0 
instance (RecreateErr f, Applicative f) => Validate f "enc-B64" "enc-B64" c TL.Text where
    validation :: Validation f "enc-B64" "enc-B64" c Text
validation = Decoding (Either UnexpectedDecodeEx) "enc-B64" "enc-B64" c Text
-> Validation f "enc-B64" "enc-B64" c Text
forall (nm :: Symbol) (f :: * -> *) c str.
(KnownSymbol nm, RecreateErr @* f, Applicative f) =>
Decoding (Either UnexpectedDecodeEx) nm nm c str
-> Validation f nm nm c str
validFromDec Decoding (Either UnexpectedDecodeEx) "enc-B64" "enc-B64" c Text
forall (f :: * -> *) c.
(UnexpectedDecodeErr @* f, Applicative f) =>
Decoding f "enc-B64" "enc-B64" c Text
decB64TL