module TD.Data.CommunityAddChatRequest
  (CommunityAddChatRequest(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

data CommunityAddChatRequest
  = CommunityAddChatRequest -- ^ Describes a request to add a chat to a community
    { CommunityAddChatRequest -> Maybe Int
chat_id        :: Maybe Int  -- ^ Identifier of the chat to be added
    , CommunityAddChatRequest -> Maybe Bool
is_hidden      :: Maybe Bool -- ^ True, if the chat will be visible only to administrators of the community
    , CommunityAddChatRequest -> Maybe Int
sender_user_id :: Maybe Int  -- ^ Identifier of the user who sent the request
    , CommunityAddChatRequest -> Maybe Int
date           :: Maybe Int  -- ^ Point in time (Unix timestamp) when the request was sent
    }
  deriving (CommunityAddChatRequest -> CommunityAddChatRequest -> Bool
(CommunityAddChatRequest -> CommunityAddChatRequest -> Bool)
-> (CommunityAddChatRequest -> CommunityAddChatRequest -> Bool)
-> Eq CommunityAddChatRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CommunityAddChatRequest -> CommunityAddChatRequest -> Bool
== :: CommunityAddChatRequest -> CommunityAddChatRequest -> Bool
$c/= :: CommunityAddChatRequest -> CommunityAddChatRequest -> Bool
/= :: CommunityAddChatRequest -> CommunityAddChatRequest -> Bool
Eq, Int -> CommunityAddChatRequest -> ShowS
[CommunityAddChatRequest] -> ShowS
CommunityAddChatRequest -> String
(Int -> CommunityAddChatRequest -> ShowS)
-> (CommunityAddChatRequest -> String)
-> ([CommunityAddChatRequest] -> ShowS)
-> Show CommunityAddChatRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CommunityAddChatRequest -> ShowS
showsPrec :: Int -> CommunityAddChatRequest -> ShowS
$cshow :: CommunityAddChatRequest -> String
show :: CommunityAddChatRequest -> String
$cshowList :: [CommunityAddChatRequest] -> ShowS
showList :: [CommunityAddChatRequest] -> ShowS
Show)

instance I.ShortShow CommunityAddChatRequest where
  shortShow :: CommunityAddChatRequest -> String
shortShow CommunityAddChatRequest
    { chat_id :: CommunityAddChatRequest -> Maybe Int
chat_id        = Maybe Int
chat_id_
    , is_hidden :: CommunityAddChatRequest -> Maybe Bool
is_hidden      = Maybe Bool
is_hidden_
    , sender_user_id :: CommunityAddChatRequest -> Maybe Int
sender_user_id = Maybe Int
sender_user_id_
    , date :: CommunityAddChatRequest -> Maybe Int
date           = Maybe Int
date_
    }
      = String
"CommunityAddChatRequest"
        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
"is_hidden"      String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_hidden_
        , String
"sender_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
sender_user_id_
        , String
"date"           String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
date_
        ]

instance AT.FromJSON CommunityAddChatRequest where
  parseJSON :: Value -> Parser CommunityAddChatRequest
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
"communityAddChatRequest" -> Value -> Parser CommunityAddChatRequest
parseCommunityAddChatRequest Value
v
      String
_                         -> Parser CommunityAddChatRequest
forall a. Monoid a => a
mempty
    
    where
      parseCommunityAddChatRequest :: A.Value -> AT.Parser CommunityAddChatRequest
      parseCommunityAddChatRequest :: Value -> Parser CommunityAddChatRequest
parseCommunityAddChatRequest = String
-> (Object -> Parser CommunityAddChatRequest)
-> Value
-> Parser CommunityAddChatRequest
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CommunityAddChatRequest" ((Object -> Parser CommunityAddChatRequest)
 -> Value -> Parser CommunityAddChatRequest)
-> (Object -> Parser CommunityAddChatRequest)
-> Value
-> Parser CommunityAddChatRequest
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 Bool
is_hidden_      <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_hidden"
        Maybe Int
sender_user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sender_user_id"
        Maybe Int
date_           <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"date"
        CommunityAddChatRequest -> Parser CommunityAddChatRequest
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CommunityAddChatRequest -> Parser CommunityAddChatRequest)
-> CommunityAddChatRequest -> Parser CommunityAddChatRequest
forall a b. (a -> b) -> a -> b
$ CommunityAddChatRequest
          { chat_id :: Maybe Int
chat_id        = Maybe Int
chat_id_
          , is_hidden :: Maybe Bool
is_hidden      = Maybe Bool
is_hidden_
          , sender_user_id :: Maybe Int
sender_user_id = Maybe Int
sender_user_id_
          , date :: Maybe Int
date           = Maybe Int
date_
          }
  parseJSON Value
_ = Parser CommunityAddChatRequest
forall a. Monoid a => a
mempty