module TD.Data.InputStoryArea
( InputStoryArea(..)
, defaultInputStoryArea
) 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.StoryAreaPosition as StoryAreaPosition
import qualified TD.Data.InputStoryAreaType as InputStoryAreaType
data InputStoryArea
= InputStoryArea
{ InputStoryArea -> Maybe StoryAreaPosition
position :: Maybe StoryAreaPosition.StoryAreaPosition
, InputStoryArea -> Maybe InputStoryAreaType
_type :: Maybe InputStoryAreaType.InputStoryAreaType
}
deriving (InputStoryArea -> InputStoryArea -> Bool
(InputStoryArea -> InputStoryArea -> Bool)
-> (InputStoryArea -> InputStoryArea -> Bool) -> Eq InputStoryArea
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputStoryArea -> InputStoryArea -> Bool
== :: InputStoryArea -> InputStoryArea -> Bool
$c/= :: InputStoryArea -> InputStoryArea -> Bool
/= :: InputStoryArea -> InputStoryArea -> Bool
Eq, Int -> InputStoryArea -> ShowS
[InputStoryArea] -> ShowS
InputStoryArea -> String
(Int -> InputStoryArea -> ShowS)
-> (InputStoryArea -> String)
-> ([InputStoryArea] -> ShowS)
-> Show InputStoryArea
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputStoryArea -> ShowS
showsPrec :: Int -> InputStoryArea -> ShowS
$cshow :: InputStoryArea -> String
show :: InputStoryArea -> String
$cshowList :: [InputStoryArea] -> ShowS
showList :: [InputStoryArea] -> ShowS
Show)
instance I.ShortShow InputStoryArea where
shortShow :: InputStoryArea -> String
shortShow InputStoryArea
{ position :: InputStoryArea -> Maybe StoryAreaPosition
position = Maybe StoryAreaPosition
position_
, _type :: InputStoryArea -> Maybe InputStoryAreaType
_type = Maybe InputStoryAreaType
_type_
}
= String
"InputStoryArea"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"position" String -> Maybe StoryAreaPosition -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StoryAreaPosition
position_
, String
"_type" String -> Maybe InputStoryAreaType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputStoryAreaType
_type_
]
instance AT.FromJSON InputStoryArea where
parseJSON :: Value -> Parser InputStoryArea
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
"inputStoryArea" -> Value -> Parser InputStoryArea
parseInputStoryArea Value
v
String
_ -> Parser InputStoryArea
forall a. Monoid a => a
mempty
where
parseInputStoryArea :: A.Value -> AT.Parser InputStoryArea
parseInputStoryArea :: Value -> Parser InputStoryArea
parseInputStoryArea = String
-> (Object -> Parser InputStoryArea)
-> Value
-> Parser InputStoryArea
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputStoryArea" ((Object -> Parser InputStoryArea)
-> Value -> Parser InputStoryArea)
-> (Object -> Parser InputStoryArea)
-> Value
-> Parser InputStoryArea
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe StoryAreaPosition
position_ <- Object
o Object -> Key -> Parser (Maybe StoryAreaPosition)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"position"
Maybe InputStoryAreaType
_type_ <- Object
o Object -> Key -> Parser (Maybe InputStoryAreaType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
InputStoryArea -> Parser InputStoryArea
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputStoryArea -> Parser InputStoryArea)
-> InputStoryArea -> Parser InputStoryArea
forall a b. (a -> b) -> a -> b
$ InputStoryArea
{ position :: Maybe StoryAreaPosition
position = Maybe StoryAreaPosition
position_
, _type :: Maybe InputStoryAreaType
_type = Maybe InputStoryAreaType
_type_
}
parseJSON Value
_ = Parser InputStoryArea
forall a. Monoid a => a
mempty
instance AT.ToJSON InputStoryArea where
toJSON :: InputStoryArea -> Value
toJSON InputStoryArea
{ position :: InputStoryArea -> Maybe StoryAreaPosition
position = Maybe StoryAreaPosition
position_
, _type :: InputStoryArea -> Maybe InputStoryAreaType
_type = Maybe InputStoryAreaType
_type_
}
= [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
"inputStoryArea"
, Key
"position" Key -> Maybe StoryAreaPosition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe StoryAreaPosition
position_
, Key
"type" Key -> Maybe InputStoryAreaType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputStoryAreaType
_type_
]
defaultInputStoryArea :: InputStoryArea
defaultInputStoryArea :: InputStoryArea
defaultInputStoryArea =
InputStoryArea
{ position :: Maybe StoryAreaPosition
position = Maybe StoryAreaPosition
forall a. Maybe a
Nothing
, _type :: Maybe InputStoryAreaType
_type = Maybe InputStoryAreaType
forall a. Maybe a
Nothing
}