module TD.Data.User
  (User(..)) 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.Usernames as Usernames
import qualified TD.Data.UserStatus as UserStatus
import qualified TD.Data.ProfilePhoto as ProfilePhoto
import qualified TD.Data.EmojiStatus as EmojiStatus
import qualified TD.Data.UserType as UserType

data User
  = User -- ^ Represents a user
    { User -> Maybe Int
_id                                :: Maybe Int                       -- ^ User identifier
    , User -> Maybe Text
first_name                         :: Maybe T.Text                    -- ^ First name of the user
    , User -> Maybe Text
last_name                          :: Maybe T.Text                    -- ^ Last name of the user
    , User -> Maybe Usernames
usernames                          :: Maybe Usernames.Usernames       -- ^ Usernames of the user; may be null
    , User -> Maybe Text
phone_number                       :: Maybe T.Text                    -- ^ Phone number of the user
    , User -> Maybe UserStatus
status                             :: Maybe UserStatus.UserStatus     -- ^ Current online status of the user
    , User -> Maybe ProfilePhoto
profile_photo                      :: Maybe ProfilePhoto.ProfilePhoto -- ^ Profile photo of the user; may be null
    , User -> Maybe Int
accent_color_id                    :: Maybe Int                       -- ^ Identifier of the accent color for name, and backgrounds of profile photo, reply header, and link preview. For Telegram Premium users only
    , User -> Maybe Int
background_custom_emoji_id         :: Maybe Int                       -- ^ Identifier of a custom emoji to be shown on the reply header and link preview background; 0 if none. For Telegram Premium users only
    , User -> Maybe Int
profile_accent_color_id            :: Maybe Int                       -- ^ Identifier of the accent color for the user's profile; -1 if none. For Telegram Premium users only
    , User -> Maybe Int
profile_background_custom_emoji_id :: Maybe Int                       -- ^ Identifier of a custom emoji to be shown on the background of the user's profile; 0 if none. For Telegram Premium users only
    , User -> Maybe EmojiStatus
emoji_status                       :: Maybe EmojiStatus.EmojiStatus   -- ^ Emoji status to be shown instead of the default Telegram Premium badge; may be null. For Telegram Premium users only
    , User -> Maybe Bool
is_contact                         :: Maybe Bool                      -- ^ The user is a contact of the current user
    , User -> Maybe Bool
is_mutual_contact                  :: Maybe Bool                      -- ^ The user is a contact of the current user and the current user is a contact of the user
    , User -> Maybe Bool
is_close_friend                    :: Maybe Bool                      -- ^ The user is a close friend of the current user; implies that the user is a contact
    , User -> Maybe Bool
is_verified                        :: Maybe Bool                      -- ^ True, if the user is verified
    , User -> Maybe Bool
is_premium                         :: Maybe Bool                      -- ^ True, if the user is a Telegram Premium user
    , User -> Maybe Bool
is_support                         :: Maybe Bool                      -- ^ True, if the user is Telegram support account
    , User -> Maybe Text
restriction_reason                 :: Maybe T.Text                    -- ^ If non-empty, it contains a human-readable description of the reason why access to this user must be restricted
    , User -> Maybe Bool
is_scam                            :: Maybe Bool                      -- ^ True, if many users reported this user as a scam
    , User -> Maybe Bool
is_fake                            :: Maybe Bool                      -- ^ True, if many users reported this user as a fake account
    , User -> Maybe Bool
has_active_stories                 :: Maybe Bool                      -- ^ True, if the user has non-expired stories available to the current user
    , User -> Maybe Bool
has_unread_active_stories          :: Maybe Bool                      -- ^ True, if the user has unread non-expired stories available to the current user
    , User -> Maybe Bool
restricts_new_chats                :: Maybe Bool                      -- ^ True, if the user may restrict new chats with non-contacts. Use canSendMessageToUser to check whether the current user can message the user or try to create a chat with them
    , User -> Maybe Bool
have_access                        :: Maybe Bool                      -- ^ If false, the user is inaccessible, and the only information known about the user is inside this class. Identifier of the user can't be passed to any method
    , User -> Maybe UserType
_type                              :: Maybe UserType.UserType         -- ^ Type of the user
    , User -> Maybe Text
language_code                      :: Maybe T.Text                    -- ^ IETF language tag of the user's language; only available to bots
    , User -> Maybe Bool
added_to_attachment_menu           :: Maybe Bool                      -- ^ True, if the user added the current bot to attachment menu; only available to bots
    }
  deriving (User -> User -> Bool
(User -> User -> Bool) -> (User -> User -> Bool) -> Eq User
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: User -> User -> Bool
== :: User -> User -> Bool
$c/= :: User -> User -> Bool
/= :: User -> User -> Bool
Eq, Int -> User -> ShowS
[User] -> ShowS
User -> String
(Int -> User -> ShowS)
-> (User -> String) -> ([User] -> ShowS) -> Show User
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> User -> ShowS
showsPrec :: Int -> User -> ShowS
$cshow :: User -> String
show :: User -> String
$cshowList :: [User] -> ShowS
showList :: [User] -> ShowS
Show)

instance I.ShortShow User where
  shortShow :: User -> String
shortShow User
    { _id :: User -> Maybe Int
_id                                = Maybe Int
_id_
    , first_name :: User -> Maybe Text
first_name                         = Maybe Text
first_name_
    , last_name :: User -> Maybe Text
last_name                          = Maybe Text
last_name_
    , usernames :: User -> Maybe Usernames
usernames                          = Maybe Usernames
usernames_
    , phone_number :: User -> Maybe Text
phone_number                       = Maybe Text
phone_number_
    , status :: User -> Maybe UserStatus
status                             = Maybe UserStatus
status_
    , profile_photo :: User -> Maybe ProfilePhoto
profile_photo                      = Maybe ProfilePhoto
profile_photo_
    , accent_color_id :: User -> Maybe Int
accent_color_id                    = Maybe Int
accent_color_id_
    , background_custom_emoji_id :: User -> Maybe Int
background_custom_emoji_id         = Maybe Int
background_custom_emoji_id_
    , profile_accent_color_id :: User -> Maybe Int
profile_accent_color_id            = Maybe Int
profile_accent_color_id_
    , profile_background_custom_emoji_id :: User -> Maybe Int
profile_background_custom_emoji_id = Maybe Int
profile_background_custom_emoji_id_
    , emoji_status :: User -> Maybe EmojiStatus
emoji_status                       = Maybe EmojiStatus
emoji_status_
    , is_contact :: User -> Maybe Bool
is_contact                         = Maybe Bool
is_contact_
    , is_mutual_contact :: User -> Maybe Bool
is_mutual_contact                  = Maybe Bool
is_mutual_contact_
    , is_close_friend :: User -> Maybe Bool
is_close_friend                    = Maybe Bool
is_close_friend_
    , is_verified :: User -> Maybe Bool
is_verified                        = Maybe Bool
is_verified_
    , is_premium :: User -> Maybe Bool
is_premium                         = Maybe Bool
is_premium_
    , is_support :: User -> Maybe Bool
is_support                         = Maybe Bool
is_support_
    , restriction_reason :: User -> Maybe Text
restriction_reason                 = Maybe Text
restriction_reason_
    , is_scam :: User -> Maybe Bool
is_scam                            = Maybe Bool
is_scam_
    , is_fake :: User -> Maybe Bool
is_fake                            = Maybe Bool
is_fake_
    , has_active_stories :: User -> Maybe Bool
has_active_stories                 = Maybe Bool
has_active_stories_
    , has_unread_active_stories :: User -> Maybe Bool
has_unread_active_stories          = Maybe Bool
has_unread_active_stories_
    , restricts_new_chats :: User -> Maybe Bool
restricts_new_chats                = Maybe Bool
restricts_new_chats_
    , have_access :: User -> Maybe Bool
have_access                        = Maybe Bool
have_access_
    , _type :: User -> Maybe UserType
_type                              = Maybe UserType
_type_
    , language_code :: User -> Maybe Text
language_code                      = Maybe Text
language_code_
    , added_to_attachment_menu :: User -> Maybe Bool
added_to_attachment_menu           = Maybe Bool
added_to_attachment_menu_
    }
      = String
"User"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_id"                                String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
        , String
"first_name"                         String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
first_name_
        , String
"last_name"                          String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
last_name_
        , String
"usernames"                          String -> Maybe Usernames -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Usernames
usernames_
        , String
"phone_number"                       String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
phone_number_
        , String
"status"                             String -> Maybe UserStatus -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UserStatus
status_
        , String
"profile_photo"                      String -> Maybe ProfilePhoto -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ProfilePhoto
profile_photo_
        , String
"accent_color_id"                    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
accent_color_id_
        , String
"background_custom_emoji_id"         String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
background_custom_emoji_id_
        , String
"profile_accent_color_id"            String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
profile_accent_color_id_
        , String
"profile_background_custom_emoji_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
profile_background_custom_emoji_id_
        , String
"emoji_status"                       String -> Maybe EmojiStatus -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe EmojiStatus
emoji_status_
        , String
"is_contact"                         String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_contact_
        , String
"is_mutual_contact"                  String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_mutual_contact_
        , String
"is_close_friend"                    String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_close_friend_
        , String
"is_verified"                        String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_verified_
        , String
"is_premium"                         String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_premium_
        , String
"is_support"                         String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_support_
        , String
"restriction_reason"                 String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
restriction_reason_
        , String
"is_scam"                            String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_scam_
        , String
"is_fake"                            String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_fake_
        , String
"has_active_stories"                 String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_active_stories_
        , String
"has_unread_active_stories"          String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_unread_active_stories_
        , String
"restricts_new_chats"                String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
restricts_new_chats_
        , String
"have_access"                        String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
have_access_
        , String
"_type"                              String -> Maybe UserType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UserType
_type_
        , String
"language_code"                      String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
language_code_
        , String
"added_to_attachment_menu"           String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
added_to_attachment_menu_
        ]

instance AT.FromJSON User where
  parseJSON :: Value -> Parser User
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
"user" -> Value -> Parser User
parseUser Value
v
      String
_      -> Parser User
forall a. Monoid a => a
mempty
    
    where
      parseUser :: A.Value -> AT.Parser User
      parseUser :: Value -> Parser User
parseUser = String -> (Object -> Parser User) -> Value -> Parser User
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"User" ((Object -> Parser User) -> Value -> Parser User)
-> (Object -> Parser User) -> Value -> Parser User
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
_id_                                <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"id"
        Maybe Text
first_name_                         <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"first_name"
        Maybe Text
last_name_                          <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"last_name"
        Maybe Usernames
usernames_                          <- Object
o Object -> Key -> Parser (Maybe Usernames)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"usernames"
        Maybe Text
phone_number_                       <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"phone_number"
        Maybe UserStatus
status_                             <- Object
o Object -> Key -> Parser (Maybe UserStatus)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"status"
        Maybe ProfilePhoto
profile_photo_                      <- Object
o Object -> Key -> Parser (Maybe ProfilePhoto)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"profile_photo"
        Maybe Int
accent_color_id_                    <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"accent_color_id"
        Maybe Int
background_custom_emoji_id_         <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"background_custom_emoji_id"
        Maybe Int
profile_accent_color_id_            <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"profile_accent_color_id"
        Maybe Int
profile_background_custom_emoji_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"profile_background_custom_emoji_id"
        Maybe EmojiStatus
emoji_status_                       <- Object
o Object -> Key -> Parser (Maybe EmojiStatus)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"emoji_status"
        Maybe Bool
is_contact_                         <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_contact"
        Maybe Bool
is_mutual_contact_                  <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_mutual_contact"
        Maybe Bool
is_close_friend_                    <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_close_friend"
        Maybe Bool
is_verified_                        <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_verified"
        Maybe Bool
is_premium_                         <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_premium"
        Maybe Bool
is_support_                         <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_support"
        Maybe Text
restriction_reason_                 <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"restriction_reason"
        Maybe Bool
is_scam_                            <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_scam"
        Maybe Bool
is_fake_                            <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_fake"
        Maybe Bool
has_active_stories_                 <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"has_active_stories"
        Maybe Bool
has_unread_active_stories_          <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"has_unread_active_stories"
        Maybe Bool
restricts_new_chats_                <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"restricts_new_chats"
        Maybe Bool
have_access_                        <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"have_access"
        Maybe UserType
_type_                              <- Object
o Object -> Key -> Parser (Maybe UserType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"type"
        Maybe Text
language_code_                      <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"language_code"
        Maybe Bool
added_to_attachment_menu_           <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"added_to_attachment_menu"
        User -> Parser User
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (User -> Parser User) -> User -> Parser User
forall a b. (a -> b) -> a -> b
$ User
          { _id :: Maybe Int
_id                                = Maybe Int
_id_
          , first_name :: Maybe Text
first_name                         = Maybe Text
first_name_
          , last_name :: Maybe Text
last_name                          = Maybe Text
last_name_
          , usernames :: Maybe Usernames
usernames                          = Maybe Usernames
usernames_
          , phone_number :: Maybe Text
phone_number                       = Maybe Text
phone_number_
          , status :: Maybe UserStatus
status                             = Maybe UserStatus
status_
          , profile_photo :: Maybe ProfilePhoto
profile_photo                      = Maybe ProfilePhoto
profile_photo_
          , accent_color_id :: Maybe Int
accent_color_id                    = Maybe Int
accent_color_id_
          , background_custom_emoji_id :: Maybe Int
background_custom_emoji_id         = Maybe Int
background_custom_emoji_id_
          , profile_accent_color_id :: Maybe Int
profile_accent_color_id            = Maybe Int
profile_accent_color_id_
          , profile_background_custom_emoji_id :: Maybe Int
profile_background_custom_emoji_id = Maybe Int
profile_background_custom_emoji_id_
          , emoji_status :: Maybe EmojiStatus
emoji_status                       = Maybe EmojiStatus
emoji_status_
          , is_contact :: Maybe Bool
is_contact                         = Maybe Bool
is_contact_
          , is_mutual_contact :: Maybe Bool
is_mutual_contact                  = Maybe Bool
is_mutual_contact_
          , is_close_friend :: Maybe Bool
is_close_friend                    = Maybe Bool
is_close_friend_
          , is_verified :: Maybe Bool
is_verified                        = Maybe Bool
is_verified_
          , is_premium :: Maybe Bool
is_premium                         = Maybe Bool
is_premium_
          , is_support :: Maybe Bool
is_support                         = Maybe Bool
is_support_
          , restriction_reason :: Maybe Text
restriction_reason                 = Maybe Text
restriction_reason_
          , is_scam :: Maybe Bool
is_scam                            = Maybe Bool
is_scam_
          , is_fake :: Maybe Bool
is_fake                            = Maybe Bool
is_fake_
          , has_active_stories :: Maybe Bool
has_active_stories                 = Maybe Bool
has_active_stories_
          , has_unread_active_stories :: Maybe Bool
has_unread_active_stories          = Maybe Bool
has_unread_active_stories_
          , restricts_new_chats :: Maybe Bool
restricts_new_chats                = Maybe Bool
restricts_new_chats_
          , have_access :: Maybe Bool
have_access                        = Maybe Bool
have_access_
          , _type :: Maybe UserType
_type                              = Maybe UserType
_type_
          , language_code :: Maybe Text
language_code                      = Maybe Text
language_code_
          , added_to_attachment_menu :: Maybe Bool
added_to_attachment_menu           = Maybe Bool
added_to_attachment_menu_
          }
  parseJSON Value
_ = Parser User
forall a. Monoid a => a
mempty