module TD.Query.TestReturnError
  (TestReturnError(..)
  ) where

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

-- | Returns the specified error and ensures that the Error object is used; for testing only. Can be called synchronously. Returns 'TD.Data.Error.Error'
data TestReturnError
  = TestReturnError
    { TestReturnError -> Maybe Error
_error :: Maybe Error.Error -- ^ The error to be returned
    }
  deriving (TestReturnError -> TestReturnError -> Bool
(TestReturnError -> TestReturnError -> Bool)
-> (TestReturnError -> TestReturnError -> Bool)
-> Eq TestReturnError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TestReturnError -> TestReturnError -> Bool
== :: TestReturnError -> TestReturnError -> Bool
$c/= :: TestReturnError -> TestReturnError -> Bool
/= :: TestReturnError -> TestReturnError -> Bool
Eq, Int -> TestReturnError -> ShowS
[TestReturnError] -> ShowS
TestReturnError -> String
(Int -> TestReturnError -> ShowS)
-> (TestReturnError -> String)
-> ([TestReturnError] -> ShowS)
-> Show TestReturnError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TestReturnError -> ShowS
showsPrec :: Int -> TestReturnError -> ShowS
$cshow :: TestReturnError -> String
show :: TestReturnError -> String
$cshowList :: [TestReturnError] -> ShowS
showList :: [TestReturnError] -> ShowS
Show)

instance I.ShortShow TestReturnError where
  shortShow :: TestReturnError -> String
shortShow
    TestReturnError
      { _error :: TestReturnError -> Maybe Error
_error = Maybe Error
_error_
      }
        = String
"TestReturnError"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"_error" String -> Maybe Error -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Error
_error_
          ]

instance AT.ToJSON TestReturnError where
  toJSON :: TestReturnError -> Value
toJSON
    TestReturnError
      { _error :: TestReturnError -> Maybe Error
_error = Maybe Error
_error_
      }
        = [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
"testReturnError"
          , Key
"error" Key -> Maybe Error -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Error
_error_
          ]