module Network.OAuth2.Experiment.Utils where

import Data.Bifunctor
import Data.ByteString (ByteString)
import Data.ByteString.Char8 qualified as BS8
import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
import Data.Text.Encoding qualified as TE
import Data.Text.Lazy qualified as TL

tlToBS :: TL.Text -> ByteString
tlToBS :: Text -> ByteString
tlToBS = Text -> ByteString
TE.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
TL.toStrict

bs8ToLazyText :: BS8.ByteString -> TL.Text
bs8ToLazyText :: ByteString -> Text
bs8ToLazyText = String -> Text
TL.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BS8.unpack

mapsToParams :: [Map TL.Text TL.Text] -> [(ByteString, ByteString)]
mapsToParams :: [Map Text Text] -> [(ByteString, ByteString)]
mapsToParams =
  forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap Text -> ByteString
tlToBS Text -> ByteString
tlToBS)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Map k a -> [(k, a)]
Map.toList
    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) k a.
(Foldable f, Ord k) =>
f (Map k a) -> Map k a
Map.unions