module TD.Data.UserType
  (UserType(..)) 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

-- | Represents the type of user. The following types are possible: regular users, deleted users and bots
data UserType
  = UserTypeRegular -- ^ A regular user
  | UserTypeDeleted -- ^ A deleted user or deleted bot. No information on the user besides the user identifier is available. It is not possible to perform any active actions on this type of user
  | UserTypeBot -- ^ A bot (see https://core.telegram.org/bots)
    { UserType -> Maybe Bool
can_be_edited                   :: Maybe Bool   -- ^ True, if the bot is owned by the current user and can be edited using the methods toggleBotUsernameIsActive, reorderBotActiveUsernames, setBotProfilePhoto, setBotName, setBotInfoDescription, and setBotInfoShortDescription
    , UserType -> Maybe Bool
can_join_groups                 :: Maybe Bool   -- ^ True, if the bot can be invited to basic group and supergroup chats
    , UserType -> Maybe Bool
can_read_all_group_messages     :: Maybe Bool   -- ^ True, if the bot can read all messages in basic group or supergroup chats and not just those addressed to the bot. In private and channel chats a bot can always read all messages
    , UserType -> Maybe Bool
has_main_web_app                :: Maybe Bool   -- ^ True, if the bot has the main Web App
    , UserType -> Maybe Bool
is_inline                       :: Maybe Bool   -- ^ True, if the bot supports inline queries
    , UserType -> Maybe Text
inline_query_placeholder        :: Maybe T.Text -- ^ Placeholder for inline queries (displayed on the application input field)
    , UserType -> Maybe Bool
need_location                   :: Maybe Bool   -- ^ True, if the location of the user is expected to be sent with every inline query to this bot
    , UserType -> Maybe Bool
can_connect_to_business         :: Maybe Bool   -- ^ True, if the bot supports connection to Telegram Business accounts
    , UserType -> Maybe Bool
can_be_added_to_attachment_menu :: Maybe Bool   -- ^ True, if the bot can be added to attachment or side menu
    , UserType -> Maybe Int
active_user_count               :: Maybe Int    -- ^ The number of recently active users of the bot
    }
  | UserTypeUnknown -- ^ No information on the user besides the user identifier is available, yet this user has not been deleted. This object is extremely rare and must be handled like a deleted user. It is not possible to perform any actions on users of this type
  deriving (UserType -> UserType -> Bool
(UserType -> UserType -> Bool)
-> (UserType -> UserType -> Bool) -> Eq UserType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserType -> UserType -> Bool
== :: UserType -> UserType -> Bool
$c/= :: UserType -> UserType -> Bool
/= :: UserType -> UserType -> Bool
Eq, Int -> UserType -> ShowS
[UserType] -> ShowS
UserType -> String
(Int -> UserType -> ShowS)
-> (UserType -> String) -> ([UserType] -> ShowS) -> Show UserType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserType -> ShowS
showsPrec :: Int -> UserType -> ShowS
$cshow :: UserType -> String
show :: UserType -> String
$cshowList :: [UserType] -> ShowS
showList :: [UserType] -> ShowS
Show)

instance I.ShortShow UserType where
  shortShow :: UserType -> String
shortShow UserType
UserTypeRegular
      = String
"UserTypeRegular"
  shortShow UserType
UserTypeDeleted
      = String
"UserTypeDeleted"
  shortShow UserTypeBot
    { can_be_edited :: UserType -> Maybe Bool
can_be_edited                   = Maybe Bool
can_be_edited_
    , can_join_groups :: UserType -> Maybe Bool
can_join_groups                 = Maybe Bool
can_join_groups_
    , can_read_all_group_messages :: UserType -> Maybe Bool
can_read_all_group_messages     = Maybe Bool
can_read_all_group_messages_
    , has_main_web_app :: UserType -> Maybe Bool
has_main_web_app                = Maybe Bool
has_main_web_app_
    , is_inline :: UserType -> Maybe Bool
is_inline                       = Maybe Bool
is_inline_
    , inline_query_placeholder :: UserType -> Maybe Text
inline_query_placeholder        = Maybe Text
inline_query_placeholder_
    , need_location :: UserType -> Maybe Bool
need_location                   = Maybe Bool
need_location_
    , can_connect_to_business :: UserType -> Maybe Bool
can_connect_to_business         = Maybe Bool
can_connect_to_business_
    , can_be_added_to_attachment_menu :: UserType -> Maybe Bool
can_be_added_to_attachment_menu = Maybe Bool
can_be_added_to_attachment_menu_
    , active_user_count :: UserType -> Maybe Int
active_user_count               = Maybe Int
active_user_count_
    }
      = String
"UserTypeBot"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"can_be_edited"                   String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_be_edited_
        , String
"can_join_groups"                 String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_join_groups_
        , String
"can_read_all_group_messages"     String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_read_all_group_messages_
        , String
"has_main_web_app"                String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_main_web_app_
        , String
"is_inline"                       String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_inline_
        , String
"inline_query_placeholder"        String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
inline_query_placeholder_
        , String
"need_location"                   String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
need_location_
        , String
"can_connect_to_business"         String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_connect_to_business_
        , String
"can_be_added_to_attachment_menu" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_be_added_to_attachment_menu_
        , String
"active_user_count"               String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
active_user_count_
        ]
  shortShow UserType
UserTypeUnknown
      = String
"UserTypeUnknown"

instance AT.FromJSON UserType where
  parseJSON :: Value -> Parser UserType
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
"userTypeRegular" -> UserType -> Parser UserType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserType
UserTypeRegular
      String
"userTypeDeleted" -> UserType -> Parser UserType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserType
UserTypeDeleted
      String
"userTypeBot"     -> Value -> Parser UserType
parseUserTypeBot Value
v
      String
"userTypeUnknown" -> UserType -> Parser UserType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserType
UserTypeUnknown
      String
_                 -> Parser UserType
forall a. Monoid a => a
mempty
    
    where
      parseUserTypeBot :: A.Value -> AT.Parser UserType
      parseUserTypeBot :: Value -> Parser UserType
parseUserTypeBot = String -> (Object -> Parser UserType) -> Value -> Parser UserType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserTypeBot" ((Object -> Parser UserType) -> Value -> Parser UserType)
-> (Object -> Parser UserType) -> Value -> Parser UserType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Bool
can_be_edited_                   <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"can_be_edited"
        Maybe Bool
can_join_groups_                 <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"can_join_groups"
        Maybe Bool
can_read_all_group_messages_     <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"can_read_all_group_messages"
        Maybe Bool
has_main_web_app_                <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"has_main_web_app"
        Maybe Bool
is_inline_                       <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_inline"
        Maybe Text
inline_query_placeholder_        <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"inline_query_placeholder"
        Maybe Bool
need_location_                   <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"need_location"
        Maybe Bool
can_connect_to_business_         <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"can_connect_to_business"
        Maybe Bool
can_be_added_to_attachment_menu_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"can_be_added_to_attachment_menu"
        Maybe Int
active_user_count_               <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"active_user_count"
        UserType -> Parser UserType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserType -> Parser UserType) -> UserType -> Parser UserType
forall a b. (a -> b) -> a -> b
$ UserTypeBot
          { can_be_edited :: Maybe Bool
can_be_edited                   = Maybe Bool
can_be_edited_
          , can_join_groups :: Maybe Bool
can_join_groups                 = Maybe Bool
can_join_groups_
          , can_read_all_group_messages :: Maybe Bool
can_read_all_group_messages     = Maybe Bool
can_read_all_group_messages_
          , has_main_web_app :: Maybe Bool
has_main_web_app                = Maybe Bool
has_main_web_app_
          , is_inline :: Maybe Bool
is_inline                       = Maybe Bool
is_inline_
          , inline_query_placeholder :: Maybe Text
inline_query_placeholder        = Maybe Text
inline_query_placeholder_
          , need_location :: Maybe Bool
need_location                   = Maybe Bool
need_location_
          , can_connect_to_business :: Maybe Bool
can_connect_to_business         = Maybe Bool
can_connect_to_business_
          , can_be_added_to_attachment_menu :: Maybe Bool
can_be_added_to_attachment_menu = Maybe Bool
can_be_added_to_attachment_menu_
          , active_user_count :: Maybe Int
active_user_count               = Maybe Int
active_user_count_
          }
  parseJSON Value
_ = Parser UserType
forall a. Monoid a => a
mempty