module TD.Data.StoryRepostInfo
  (StoryRepostInfo(..)) 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.StoryOrigin as StoryOrigin

data StoryRepostInfo
  = StoryRepostInfo -- ^ Contains information about original story that was reposted
    { StoryRepostInfo -> Maybe StoryOrigin
origin              :: Maybe StoryOrigin.StoryOrigin -- ^ Origin of the story that was reposted
    , StoryRepostInfo -> Maybe Bool
is_content_modified :: Maybe Bool                    -- ^ True, if story content was modified during reposting; otherwise, story wasn't modified
    }
  deriving (StoryRepostInfo -> StoryRepostInfo -> Bool
(StoryRepostInfo -> StoryRepostInfo -> Bool)
-> (StoryRepostInfo -> StoryRepostInfo -> Bool)
-> Eq StoryRepostInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StoryRepostInfo -> StoryRepostInfo -> Bool
== :: StoryRepostInfo -> StoryRepostInfo -> Bool
$c/= :: StoryRepostInfo -> StoryRepostInfo -> Bool
/= :: StoryRepostInfo -> StoryRepostInfo -> Bool
Eq, Int -> StoryRepostInfo -> ShowS
[StoryRepostInfo] -> ShowS
StoryRepostInfo -> String
(Int -> StoryRepostInfo -> ShowS)
-> (StoryRepostInfo -> String)
-> ([StoryRepostInfo] -> ShowS)
-> Show StoryRepostInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StoryRepostInfo -> ShowS
showsPrec :: Int -> StoryRepostInfo -> ShowS
$cshow :: StoryRepostInfo -> String
show :: StoryRepostInfo -> String
$cshowList :: [StoryRepostInfo] -> ShowS
showList :: [StoryRepostInfo] -> ShowS
Show)

instance I.ShortShow StoryRepostInfo where
  shortShow :: StoryRepostInfo -> String
shortShow StoryRepostInfo
    { origin :: StoryRepostInfo -> Maybe StoryOrigin
origin              = Maybe StoryOrigin
origin_
    , is_content_modified :: StoryRepostInfo -> Maybe Bool
is_content_modified = Maybe Bool
is_content_modified_
    }
      = String
"StoryRepostInfo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"origin"              String -> Maybe StoryOrigin -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StoryOrigin
origin_
        , String
"is_content_modified" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_content_modified_
        ]

instance AT.FromJSON StoryRepostInfo where
  parseJSON :: Value -> Parser StoryRepostInfo
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
"storyRepostInfo" -> Value -> Parser StoryRepostInfo
parseStoryRepostInfo Value
v
      String
_                 -> Parser StoryRepostInfo
forall a. Monoid a => a
mempty
    
    where
      parseStoryRepostInfo :: A.Value -> AT.Parser StoryRepostInfo
      parseStoryRepostInfo :: Value -> Parser StoryRepostInfo
parseStoryRepostInfo = String
-> (Object -> Parser StoryRepostInfo)
-> Value
-> Parser StoryRepostInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StoryRepostInfo" ((Object -> Parser StoryRepostInfo)
 -> Value -> Parser StoryRepostInfo)
-> (Object -> Parser StoryRepostInfo)
-> Value
-> Parser StoryRepostInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe StoryOrigin
origin_              <- Object
o Object -> Key -> Parser (Maybe StoryOrigin)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"origin"
        Maybe Bool
is_content_modified_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_content_modified"
        StoryRepostInfo -> Parser StoryRepostInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StoryRepostInfo -> Parser StoryRepostInfo)
-> StoryRepostInfo -> Parser StoryRepostInfo
forall a b. (a -> b) -> a -> b
$ StoryRepostInfo
          { origin :: Maybe StoryOrigin
origin              = Maybe StoryOrigin
origin_
          , is_content_modified :: Maybe Bool
is_content_modified = Maybe Bool
is_content_modified_
          }
  parseJSON Value
_ = Parser StoryRepostInfo
forall a. Monoid a => a
mempty