module TD.Data.SharedChat
  (SharedChat(..)) 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 SharedChat
  = SharedChat -- ^ Contains information about a chat shared with a bot
    { SharedChat -> Maybe Int
chat_id  :: Maybe Int         -- ^ Chat identifier
    , SharedChat -> Maybe Text
title    :: Maybe T.Text      -- ^ Title of the chat; for bots only
    , SharedChat -> Maybe Text
username :: Maybe T.Text      -- ^ Username of the chat; for bots only
    , SharedChat -> Maybe Photo
photo    :: Maybe Photo.Photo -- ^ Photo of the chat; for bots only; may be null
    }
  deriving (SharedChat -> SharedChat -> Bool
(SharedChat -> SharedChat -> Bool)
-> (SharedChat -> SharedChat -> Bool) -> Eq SharedChat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SharedChat -> SharedChat -> Bool
== :: SharedChat -> SharedChat -> Bool
$c/= :: SharedChat -> SharedChat -> Bool
/= :: SharedChat -> SharedChat -> Bool
Eq, Int -> SharedChat -> ShowS
[SharedChat] -> ShowS
SharedChat -> String
(Int -> SharedChat -> ShowS)
-> (SharedChat -> String)
-> ([SharedChat] -> ShowS)
-> Show SharedChat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SharedChat -> ShowS
showsPrec :: Int -> SharedChat -> ShowS
$cshow :: SharedChat -> String
show :: SharedChat -> String
$cshowList :: [SharedChat] -> ShowS
showList :: [SharedChat] -> ShowS
Show)

instance I.ShortShow SharedChat where
  shortShow :: SharedChat -> String
shortShow SharedChat
    { chat_id :: SharedChat -> Maybe Int
chat_id  = Maybe Int
chat_id_
    , title :: SharedChat -> Maybe Text
title    = Maybe Text
title_
    , username :: SharedChat -> Maybe Text
username = Maybe Text
username_
    , photo :: SharedChat -> Maybe Photo
photo    = Maybe Photo
photo_
    }
      = String
"SharedChat"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"chat_id"  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
        , String
"title"    String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , String
"username" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
username_
        , String
"photo"    String -> Maybe Photo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Photo
photo_
        ]

instance AT.FromJSON SharedChat where
  parseJSON :: Value -> Parser SharedChat
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
"sharedChat" -> Value -> Parser SharedChat
parseSharedChat Value
v
      String
_            -> Parser SharedChat
forall a. Monoid a => a
mempty
    
    where
      parseSharedChat :: A.Value -> AT.Parser SharedChat
      parseSharedChat :: Value -> Parser SharedChat
parseSharedChat = String
-> (Object -> Parser SharedChat) -> Value -> Parser SharedChat
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"SharedChat" ((Object -> Parser SharedChat) -> Value -> Parser SharedChat)
-> (Object -> Parser SharedChat) -> Value -> Parser SharedChat
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
chat_id_  <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"chat_id"
        Maybe Text
title_    <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"title"
        Maybe Text
username_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"username"
        Maybe Photo
photo_    <- Object
o Object -> Key -> Parser (Maybe Photo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"photo"
        SharedChat -> Parser SharedChat
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SharedChat -> Parser SharedChat)
-> SharedChat -> Parser SharedChat
forall a b. (a -> b) -> a -> b
$ SharedChat
          { chat_id :: Maybe Int
chat_id  = Maybe Int
chat_id_
          , title :: Maybe Text
title    = Maybe Text
title_
          , username :: Maybe Text
username = Maybe Text
username_
          , photo :: Maybe Photo
photo    = Maybe Photo
photo_
          }
  parseJSON Value
_ = Parser SharedChat
forall a. Monoid a => a
mempty