module TD.Data.TestVectorInt
  (TestVectorInt(..)) where

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

data TestVectorInt
  = TestVectorInt -- ^ A simple object containing a vector of numbers; for testing only
    { TestVectorInt -> Maybe [Int]
value :: Maybe [Int] -- ^ Vector of numbers
    }
  deriving (TestVectorInt -> TestVectorInt -> Bool
(TestVectorInt -> TestVectorInt -> Bool)
-> (TestVectorInt -> TestVectorInt -> Bool) -> Eq TestVectorInt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TestVectorInt -> TestVectorInt -> Bool
== :: TestVectorInt -> TestVectorInt -> Bool
$c/= :: TestVectorInt -> TestVectorInt -> Bool
/= :: TestVectorInt -> TestVectorInt -> Bool
Eq, Int -> TestVectorInt -> ShowS
[TestVectorInt] -> ShowS
TestVectorInt -> String
(Int -> TestVectorInt -> ShowS)
-> (TestVectorInt -> String)
-> ([TestVectorInt] -> ShowS)
-> Show TestVectorInt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TestVectorInt -> ShowS
showsPrec :: Int -> TestVectorInt -> ShowS
$cshow :: TestVectorInt -> String
show :: TestVectorInt -> String
$cshowList :: [TestVectorInt] -> ShowS
showList :: [TestVectorInt] -> ShowS
Show)

instance I.ShortShow TestVectorInt where
  shortShow :: TestVectorInt -> String
shortShow TestVectorInt
    { value :: TestVectorInt -> Maybe [Int]
value = Maybe [Int]
value_
    }
      = String
"TestVectorInt"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"value" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
value_
        ]

instance AT.FromJSON TestVectorInt where
  parseJSON :: Value -> Parser TestVectorInt
parseJSON v :: Value
v@(AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"testVectorInt" -> Value -> Parser TestVectorInt
parseTestVectorInt Value
v
      String
_               -> Parser TestVectorInt
forall a. Monoid a => a
mempty
    
    where
      parseTestVectorInt :: A.Value -> AT.Parser TestVectorInt
      parseTestVectorInt :: Value -> Parser TestVectorInt
parseTestVectorInt = String
-> (Object -> Parser TestVectorInt)
-> Value
-> Parser TestVectorInt
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TestVectorInt" ((Object -> Parser TestVectorInt) -> Value -> Parser TestVectorInt)
-> (Object -> Parser TestVectorInt)
-> Value
-> Parser TestVectorInt
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [Int]
value_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"value"
        TestVectorInt -> Parser TestVectorInt
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TestVectorInt -> Parser TestVectorInt)
-> TestVectorInt -> Parser TestVectorInt
forall a b. (a -> b) -> a -> b
$ TestVectorInt
          { value :: Maybe [Int]
value = Maybe [Int]
value_
          }
  parseJSON Value
_ = Parser TestVectorInt
forall a. Monoid a => a
mempty