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

data OauthLinkInfo
  = OauthLinkInfo -- ^ Information about the OAuth authorization
    { OauthLinkInfo -> Maybe Int
user_id                     :: Maybe Int      -- ^ Identifier of the user for which the link was generated; may be 0 if unknown. The corresponding user may be unknown. If the user is logged in the app, then they must be chosen for authorization by default
    , OauthLinkInfo -> Maybe Text
url                         :: Maybe T.Text   -- ^ An HTTP URL where the user authorizes
    , OauthLinkInfo -> Maybe Text
domain                      :: Maybe T.Text   -- ^ A domain of the URL
    , OauthLinkInfo -> Maybe Int
bot_user_id                 :: Maybe Int      -- ^ User identifier of a bot linked with the website
    , OauthLinkInfo -> Maybe Bool
request_write_access        :: Maybe Bool     -- ^ True, if the user must be asked for the permission to the bot to send them messages
    , OauthLinkInfo -> Maybe Bool
request_phone_number_access :: Maybe Bool     -- ^ True, if the user must be asked for the permission to share their phone number
    , OauthLinkInfo -> Maybe Text
browser                     :: Maybe T.Text   -- ^ The version of a browser used for the authorization
    , OauthLinkInfo -> Maybe Text
platform                    :: Maybe T.Text   -- ^ Operating system the browser is running on
    , OauthLinkInfo -> Maybe Text
ip_address                  :: Maybe T.Text   -- ^ IP address from which the authorization is performed, in human-readable format
    , OauthLinkInfo -> Maybe Text
location                    :: Maybe T.Text   -- ^ Human-readable description of a country and a region from which the authorization is performed, based on the IP address
    , OauthLinkInfo -> Maybe Bool
match_code_first            :: Maybe Bool     -- ^ True, if code matching dialog must be shown first and checkOauthRequestMatchCode must be called before acceptOauthRequest. Otherwise, checkOauthRequestMatchCode must not be called
    , OauthLinkInfo -> Maybe [Text]
match_codes                 :: Maybe [T.Text] -- ^ The list of codes to match; may be empty if irrelevant
    }
  deriving (OauthLinkInfo -> OauthLinkInfo -> Bool
(OauthLinkInfo -> OauthLinkInfo -> Bool)
-> (OauthLinkInfo -> OauthLinkInfo -> Bool) -> Eq OauthLinkInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OauthLinkInfo -> OauthLinkInfo -> Bool
== :: OauthLinkInfo -> OauthLinkInfo -> Bool
$c/= :: OauthLinkInfo -> OauthLinkInfo -> Bool
/= :: OauthLinkInfo -> OauthLinkInfo -> Bool
Eq, Int -> OauthLinkInfo -> ShowS
[OauthLinkInfo] -> ShowS
OauthLinkInfo -> String
(Int -> OauthLinkInfo -> ShowS)
-> (OauthLinkInfo -> String)
-> ([OauthLinkInfo] -> ShowS)
-> Show OauthLinkInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OauthLinkInfo -> ShowS
showsPrec :: Int -> OauthLinkInfo -> ShowS
$cshow :: OauthLinkInfo -> String
show :: OauthLinkInfo -> String
$cshowList :: [OauthLinkInfo] -> ShowS
showList :: [OauthLinkInfo] -> ShowS
Show)

instance I.ShortShow OauthLinkInfo where
  shortShow :: OauthLinkInfo -> String
shortShow OauthLinkInfo
    { user_id :: OauthLinkInfo -> Maybe Int
user_id                     = Maybe Int
user_id_
    , url :: OauthLinkInfo -> Maybe Text
url                         = Maybe Text
url_
    , domain :: OauthLinkInfo -> Maybe Text
domain                      = Maybe Text
domain_
    , bot_user_id :: OauthLinkInfo -> Maybe Int
bot_user_id                 = Maybe Int
bot_user_id_
    , request_write_access :: OauthLinkInfo -> Maybe Bool
request_write_access        = Maybe Bool
request_write_access_
    , request_phone_number_access :: OauthLinkInfo -> Maybe Bool
request_phone_number_access = Maybe Bool
request_phone_number_access_
    , browser :: OauthLinkInfo -> Maybe Text
browser                     = Maybe Text
browser_
    , platform :: OauthLinkInfo -> Maybe Text
platform                    = Maybe Text
platform_
    , ip_address :: OauthLinkInfo -> Maybe Text
ip_address                  = Maybe Text
ip_address_
    , location :: OauthLinkInfo -> Maybe Text
location                    = Maybe Text
location_
    , match_code_first :: OauthLinkInfo -> Maybe Bool
match_code_first            = Maybe Bool
match_code_first_
    , match_codes :: OauthLinkInfo -> Maybe [Text]
match_codes                 = Maybe [Text]
match_codes_
    }
      = String
"OauthLinkInfo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"user_id"                     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
        , String
"url"                         String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
        , String
"domain"                      String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
domain_
        , String
"bot_user_id"                 String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
bot_user_id_
        , String
"request_write_access"        String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
request_write_access_
        , String
"request_phone_number_access" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
request_phone_number_access_
        , String
"browser"                     String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
browser_
        , String
"platform"                    String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
platform_
        , String
"ip_address"                  String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
ip_address_
        , String
"location"                    String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
location_
        , String
"match_code_first"            String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
match_code_first_
        , String
"match_codes"                 String -> Maybe [Text] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Text]
match_codes_
        ]

instance AT.FromJSON OauthLinkInfo where
  parseJSON :: Value -> Parser OauthLinkInfo
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
"oauthLinkInfo" -> Value -> Parser OauthLinkInfo
parseOauthLinkInfo Value
v
      String
_               -> Parser OauthLinkInfo
forall a. Monoid a => a
mempty
    
    where
      parseOauthLinkInfo :: A.Value -> AT.Parser OauthLinkInfo
      parseOauthLinkInfo :: Value -> Parser OauthLinkInfo
parseOauthLinkInfo = String
-> (Object -> Parser OauthLinkInfo)
-> Value
-> Parser OauthLinkInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"OauthLinkInfo" ((Object -> Parser OauthLinkInfo) -> Value -> Parser OauthLinkInfo)
-> (Object -> Parser OauthLinkInfo)
-> Value
-> Parser OauthLinkInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
user_id_                     <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"user_id"
        Maybe Text
url_                         <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"url"
        Maybe Text
domain_                      <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"domain"
        Maybe Int
bot_user_id_                 <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"bot_user_id"
        Maybe Bool
request_write_access_        <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"request_write_access"
        Maybe Bool
request_phone_number_access_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"request_phone_number_access"
        Maybe Text
browser_                     <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"browser"
        Maybe Text
platform_                    <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"platform"
        Maybe Text
ip_address_                  <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"ip_address"
        Maybe Text
location_                    <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"location"
        Maybe Bool
match_code_first_            <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"match_code_first"
        Maybe [Text]
match_codes_                 <- Object
o Object -> Key -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"match_codes"
        OauthLinkInfo -> Parser OauthLinkInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (OauthLinkInfo -> Parser OauthLinkInfo)
-> OauthLinkInfo -> Parser OauthLinkInfo
forall a b. (a -> b) -> a -> b
$ OauthLinkInfo
          { user_id :: Maybe Int
user_id                     = Maybe Int
user_id_
          , url :: Maybe Text
url                         = Maybe Text
url_
          , domain :: Maybe Text
domain                      = Maybe Text
domain_
          , bot_user_id :: Maybe Int
bot_user_id                 = Maybe Int
bot_user_id_
          , request_write_access :: Maybe Bool
request_write_access        = Maybe Bool
request_write_access_
          , request_phone_number_access :: Maybe Bool
request_phone_number_access = Maybe Bool
request_phone_number_access_
          , browser :: Maybe Text
browser                     = Maybe Text
browser_
          , platform :: Maybe Text
platform                    = Maybe Text
platform_
          , ip_address :: Maybe Text
ip_address                  = Maybe Text
ip_address_
          , location :: Maybe Text
location                    = Maybe Text
location_
          , match_code_first :: Maybe Bool
match_code_first            = Maybe Bool
match_code_first_
          , match_codes :: Maybe [Text]
match_codes                 = Maybe [Text]
match_codes_
          }
  parseJSON Value
_ = Parser OauthLinkInfo
forall a. Monoid a => a
mempty