module TD.Data.DiffEntityType
(DiffEntityType(..)) 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
data DiffEntityType
= DiffEntityTypeInsert
| DiffEntityTypeReplace
{ DiffEntityType -> Maybe Text
old_text :: Maybe T.Text
}
| DiffEntityTypeDelete
deriving (DiffEntityType -> DiffEntityType -> Bool
(DiffEntityType -> DiffEntityType -> Bool)
-> (DiffEntityType -> DiffEntityType -> Bool) -> Eq DiffEntityType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DiffEntityType -> DiffEntityType -> Bool
== :: DiffEntityType -> DiffEntityType -> Bool
$c/= :: DiffEntityType -> DiffEntityType -> Bool
/= :: DiffEntityType -> DiffEntityType -> Bool
Eq, Int -> DiffEntityType -> ShowS
[DiffEntityType] -> ShowS
DiffEntityType -> String
(Int -> DiffEntityType -> ShowS)
-> (DiffEntityType -> String)
-> ([DiffEntityType] -> ShowS)
-> Show DiffEntityType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DiffEntityType -> ShowS
showsPrec :: Int -> DiffEntityType -> ShowS
$cshow :: DiffEntityType -> String
show :: DiffEntityType -> String
$cshowList :: [DiffEntityType] -> ShowS
showList :: [DiffEntityType] -> ShowS
Show)
instance I.ShortShow DiffEntityType where
shortShow :: DiffEntityType -> String
shortShow DiffEntityType
DiffEntityTypeInsert
= String
"DiffEntityTypeInsert"
shortShow DiffEntityTypeReplace
{ old_text :: DiffEntityType -> Maybe Text
old_text = Maybe Text
old_text_
}
= String
"DiffEntityTypeReplace"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"old_text" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
old_text_
]
shortShow DiffEntityType
DiffEntityTypeDelete
= String
"DiffEntityTypeDelete"
instance AT.FromJSON DiffEntityType where
parseJSON :: Value -> Parser DiffEntityType
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
"diffEntityTypeInsert" -> DiffEntityType -> Parser DiffEntityType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure DiffEntityType
DiffEntityTypeInsert
String
"diffEntityTypeReplace" -> Value -> Parser DiffEntityType
parseDiffEntityTypeReplace Value
v
String
"diffEntityTypeDelete" -> DiffEntityType -> Parser DiffEntityType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure DiffEntityType
DiffEntityTypeDelete
String
_ -> Parser DiffEntityType
forall a. Monoid a => a
mempty
where
parseDiffEntityTypeReplace :: A.Value -> AT.Parser DiffEntityType
parseDiffEntityTypeReplace :: Value -> Parser DiffEntityType
parseDiffEntityTypeReplace = String
-> (Object -> Parser DiffEntityType)
-> Value
-> Parser DiffEntityType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"DiffEntityTypeReplace" ((Object -> Parser DiffEntityType)
-> Value -> Parser DiffEntityType)
-> (Object -> Parser DiffEntityType)
-> Value
-> Parser DiffEntityType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
old_text_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"old_text"
DiffEntityType -> Parser DiffEntityType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (DiffEntityType -> Parser DiffEntityType)
-> DiffEntityType -> Parser DiffEntityType
forall a b. (a -> b) -> a -> b
$ DiffEntityTypeReplace
{ old_text :: Maybe Text
old_text = Maybe Text
old_text_
}
parseJSON Value
_ = Parser DiffEntityType
forall a. Monoid a => a
mempty