module TD.Query.ReportWebProxyCarrierError
  (ReportWebProxyCarrierError(..)
  , defaultReportWebProxyCarrierError
  ) where

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

-- | Reports that a web proxy carrier failed. TDLib closes the carrier and decides whether and when to request a new one. Can be called before authorization. Returns 'TD.Data.Ok.Ok'
data ReportWebProxyCarrierError
  = ReportWebProxyCarrierError
    { ReportWebProxyCarrierError -> Maybe Int
carrier_id :: Maybe Int                                       -- ^ Identifier of the carrier
    , ReportWebProxyCarrierError -> Maybe WebProxyCarrierError
_error     :: Maybe WebProxyCarrierError.WebProxyCarrierError -- ^ The error
    }
  deriving (ReportWebProxyCarrierError -> ReportWebProxyCarrierError -> Bool
(ReportWebProxyCarrierError -> ReportWebProxyCarrierError -> Bool)
-> (ReportWebProxyCarrierError
    -> ReportWebProxyCarrierError -> Bool)
-> Eq ReportWebProxyCarrierError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReportWebProxyCarrierError -> ReportWebProxyCarrierError -> Bool
== :: ReportWebProxyCarrierError -> ReportWebProxyCarrierError -> Bool
$c/= :: ReportWebProxyCarrierError -> ReportWebProxyCarrierError -> Bool
/= :: ReportWebProxyCarrierError -> ReportWebProxyCarrierError -> Bool
Eq, Int -> ReportWebProxyCarrierError -> ShowS
[ReportWebProxyCarrierError] -> ShowS
ReportWebProxyCarrierError -> String
(Int -> ReportWebProxyCarrierError -> ShowS)
-> (ReportWebProxyCarrierError -> String)
-> ([ReportWebProxyCarrierError] -> ShowS)
-> Show ReportWebProxyCarrierError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReportWebProxyCarrierError -> ShowS
showsPrec :: Int -> ReportWebProxyCarrierError -> ShowS
$cshow :: ReportWebProxyCarrierError -> String
show :: ReportWebProxyCarrierError -> String
$cshowList :: [ReportWebProxyCarrierError] -> ShowS
showList :: [ReportWebProxyCarrierError] -> ShowS
Show)

instance I.ShortShow ReportWebProxyCarrierError where
  shortShow :: ReportWebProxyCarrierError -> String
shortShow
    ReportWebProxyCarrierError
      { carrier_id :: ReportWebProxyCarrierError -> Maybe Int
carrier_id = Maybe Int
carrier_id_
      , _error :: ReportWebProxyCarrierError -> Maybe WebProxyCarrierError
_error     = Maybe WebProxyCarrierError
_error_
      }
        = String
"ReportWebProxyCarrierError"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"carrier_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
carrier_id_
          , String
"_error"     String -> Maybe WebProxyCarrierError -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe WebProxyCarrierError
_error_
          ]

instance AT.ToJSON ReportWebProxyCarrierError where
  toJSON :: ReportWebProxyCarrierError -> Value
toJSON
    ReportWebProxyCarrierError
      { carrier_id :: ReportWebProxyCarrierError -> Maybe Int
carrier_id = Maybe Int
carrier_id_
      , _error :: ReportWebProxyCarrierError -> Maybe WebProxyCarrierError
_error     = Maybe WebProxyCarrierError
_error_
      }
        = [Pair] -> Value
A.object
          [ Key
"@type"      Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"reportWebProxyCarrierError"
          , Key
"carrier_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
carrier_id_
          , Key
"error"      Key -> Maybe WebProxyCarrierError -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe WebProxyCarrierError
_error_
          ]

defaultReportWebProxyCarrierError :: ReportWebProxyCarrierError
defaultReportWebProxyCarrierError :: ReportWebProxyCarrierError
defaultReportWebProxyCarrierError =
  ReportWebProxyCarrierError
    { carrier_id :: Maybe Int
carrier_id = Maybe Int
forall a. Maybe a
Nothing
    , _error :: Maybe WebProxyCarrierError
_error     = Maybe WebProxyCarrierError
forall a. Maybe a
Nothing
    }