module TD.Data.PageBlockRelatedArticle
  (PageBlockRelatedArticle(..)) 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
import qualified TD.Data.Photo as Photo

data PageBlockRelatedArticle
  = PageBlockRelatedArticle -- ^ Contains information about a related article
    { PageBlockRelatedArticle -> Maybe Text
url          :: Maybe T.Text      -- ^ Related article URL
    , PageBlockRelatedArticle -> Maybe Text
title        :: Maybe T.Text      -- ^ Article title; may be empty
    , PageBlockRelatedArticle -> Maybe Text
description  :: Maybe T.Text      -- ^ Article description; may be empty
    , PageBlockRelatedArticle -> Maybe Photo
photo        :: Maybe Photo.Photo -- ^ Article photo; may be null
    , PageBlockRelatedArticle -> Maybe Text
author       :: Maybe T.Text      -- ^ Article author; may be empty
    , PageBlockRelatedArticle -> Maybe Int
publish_date :: Maybe Int         -- ^ Point in time (Unix timestamp) when the article was published; 0 if unknown
    }
  deriving (PageBlockRelatedArticle -> PageBlockRelatedArticle -> Bool
(PageBlockRelatedArticle -> PageBlockRelatedArticle -> Bool)
-> (PageBlockRelatedArticle -> PageBlockRelatedArticle -> Bool)
-> Eq PageBlockRelatedArticle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PageBlockRelatedArticle -> PageBlockRelatedArticle -> Bool
== :: PageBlockRelatedArticle -> PageBlockRelatedArticle -> Bool
$c/= :: PageBlockRelatedArticle -> PageBlockRelatedArticle -> Bool
/= :: PageBlockRelatedArticle -> PageBlockRelatedArticle -> Bool
Eq, Int -> PageBlockRelatedArticle -> ShowS
[PageBlockRelatedArticle] -> ShowS
PageBlockRelatedArticle -> String
(Int -> PageBlockRelatedArticle -> ShowS)
-> (PageBlockRelatedArticle -> String)
-> ([PageBlockRelatedArticle] -> ShowS)
-> Show PageBlockRelatedArticle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PageBlockRelatedArticle -> ShowS
showsPrec :: Int -> PageBlockRelatedArticle -> ShowS
$cshow :: PageBlockRelatedArticle -> String
show :: PageBlockRelatedArticle -> String
$cshowList :: [PageBlockRelatedArticle] -> ShowS
showList :: [PageBlockRelatedArticle] -> ShowS
Show)

instance I.ShortShow PageBlockRelatedArticle where
  shortShow :: PageBlockRelatedArticle -> String
shortShow PageBlockRelatedArticle
    { url :: PageBlockRelatedArticle -> Maybe Text
url          = Maybe Text
url_
    , title :: PageBlockRelatedArticle -> Maybe Text
title        = Maybe Text
title_
    , description :: PageBlockRelatedArticle -> Maybe Text
description  = Maybe Text
description_
    , photo :: PageBlockRelatedArticle -> Maybe Photo
photo        = Maybe Photo
photo_
    , author :: PageBlockRelatedArticle -> Maybe Text
author       = Maybe Text
author_
    , publish_date :: PageBlockRelatedArticle -> Maybe Int
publish_date = Maybe Int
publish_date_
    }
      = String
"PageBlockRelatedArticle"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"url"          String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
        , String
"title"        String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , String
"description"  String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
description_
        , String
"photo"        String -> Maybe Photo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Photo
photo_
        , String
"author"       String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
author_
        , String
"publish_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
publish_date_
        ]

instance AT.FromJSON PageBlockRelatedArticle where
  parseJSON :: Value -> Parser PageBlockRelatedArticle
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
"pageBlockRelatedArticle" -> Value -> Parser PageBlockRelatedArticle
parsePageBlockRelatedArticle Value
v
      String
_                         -> Parser PageBlockRelatedArticle
forall a. Monoid a => a
mempty
    
    where
      parsePageBlockRelatedArticle :: A.Value -> AT.Parser PageBlockRelatedArticle
      parsePageBlockRelatedArticle :: Value -> Parser PageBlockRelatedArticle
parsePageBlockRelatedArticle = String
-> (Object -> Parser PageBlockRelatedArticle)
-> Value
-> Parser PageBlockRelatedArticle
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PageBlockRelatedArticle" ((Object -> Parser PageBlockRelatedArticle)
 -> Value -> Parser PageBlockRelatedArticle)
-> (Object -> Parser PageBlockRelatedArticle)
-> Value
-> Parser PageBlockRelatedArticle
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
url_          <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"url"
        Maybe Text
title_        <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"title"
        Maybe Text
description_  <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"description"
        Maybe Photo
photo_        <- Object
o Object -> Key -> Parser (Maybe Photo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"photo"
        Maybe Text
author_       <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"author"
        Maybe Int
publish_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"publish_date"
        PageBlockRelatedArticle -> Parser PageBlockRelatedArticle
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PageBlockRelatedArticle -> Parser PageBlockRelatedArticle)
-> PageBlockRelatedArticle -> Parser PageBlockRelatedArticle
forall a b. (a -> b) -> a -> b
$ PageBlockRelatedArticle
          { url :: Maybe Text
url          = Maybe Text
url_
          , title :: Maybe Text
title        = Maybe Text
title_
          , description :: Maybe Text
description  = Maybe Text
description_
          , photo :: Maybe Photo
photo        = Maybe Photo
photo_
          , author :: Maybe Text
author       = Maybe Text
author_
          , publish_date :: Maybe Int
publish_date = Maybe Int
publish_date_
          }
  parseJSON Value
_ = Parser PageBlockRelatedArticle
forall a. Monoid a => a
mempty