module Cardano.Api.Via.ShowOf
  ( ShowOf (..)
  )
where

import           Data.Aeson
import qualified Data.Aeson.Key as Key
import           Data.Aeson.Types
import qualified Data.Text as Text
import           Prettyprinter

newtype ShowOf a = ShowOf a

instance Show a => Show (ShowOf a) where
  show :: ShowOf a -> String
show (ShowOf a
a) = a -> String
forall a. Show a => a -> String
show a
a

instance Show a => Pretty (ShowOf a) where
  pretty :: forall ann. ShowOf a -> Doc ann
pretty = ShowOf a -> Doc ann
forall a ann. Show a => a -> Doc ann
viaShow

instance Show a => ToJSON (ShowOf a) where
  toJSON :: ShowOf a -> Value
toJSON (ShowOf a
a) = Text -> Value
String (String -> Text
Text.pack (a -> String
forall a. Show a => a -> String
show a
a))

instance Show a => ToJSONKey (ShowOf a) where
  toJSONKey :: ToJSONKeyFunction (ShowOf a)
toJSONKey = (ShowOf a -> Key) -> ToJSONKeyFunction (ShowOf a)
forall a. (a -> Key) -> ToJSONKeyFunction a
toJSONKeyKey (String -> Key
Key.fromString (String -> Key) -> (ShowOf a -> String) -> ShowOf a -> Key
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowOf a -> String
forall a. Show a => a -> String
show)