module TD.Query.GetJsonValue
  (GetJsonValue(..)
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T

-- | Converts a JSON-serialized string to corresponding JsonValue object. Can be called synchronously. Returns 'TD.Data.JsonValue.JsonValue'
data GetJsonValue
  = GetJsonValue
    { GetJsonValue -> Maybe Text
json :: Maybe T.Text -- ^ The JSON-serialized string
    }
  deriving (GetJsonValue -> GetJsonValue -> Bool
(GetJsonValue -> GetJsonValue -> Bool)
-> (GetJsonValue -> GetJsonValue -> Bool) -> Eq GetJsonValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetJsonValue -> GetJsonValue -> Bool
== :: GetJsonValue -> GetJsonValue -> Bool
$c/= :: GetJsonValue -> GetJsonValue -> Bool
/= :: GetJsonValue -> GetJsonValue -> Bool
Eq, Int -> GetJsonValue -> ShowS
[GetJsonValue] -> ShowS
GetJsonValue -> String
(Int -> GetJsonValue -> ShowS)
-> (GetJsonValue -> String)
-> ([GetJsonValue] -> ShowS)
-> Show GetJsonValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetJsonValue -> ShowS
showsPrec :: Int -> GetJsonValue -> ShowS
$cshow :: GetJsonValue -> String
show :: GetJsonValue -> String
$cshowList :: [GetJsonValue] -> ShowS
showList :: [GetJsonValue] -> ShowS
Show)

instance I.ShortShow GetJsonValue where
  shortShow :: GetJsonValue -> String
shortShow
    GetJsonValue
      { json :: GetJsonValue -> Maybe Text
json = Maybe Text
json_
      }
        = String
"GetJsonValue"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"json" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
json_
          ]

instance AT.ToJSON GetJsonValue where
  toJSON :: GetJsonValue -> Value
toJSON
    GetJsonValue
      { json :: GetJsonValue -> Maybe Text
json = Maybe Text
json_
      }
        = [Pair] -> Value
A.object
          [ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"getJsonValue"
          , Key
"json"  Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
json_
          ]