module TD.Data.WebDomainException
  (WebDomainException(..)) 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 WebDomainException
  = WebDomainException -- ^ Describes an exception for built-in browser usage
    { WebDomainException -> Maybe Text
url                     :: Maybe T.Text -- ^ URL for which the exception is done
    , WebDomainException -> Maybe Text
domain                  :: Maybe T.Text -- ^ Domain of the URL. All URLs on the domain and subdomains of the domain are subject to the exception
    , WebDomainException -> Maybe Text
title                   :: Maybe T.Text -- ^ Title of the website
    , WebDomainException -> Maybe Int
favicon_custom_emoji_id :: Maybe Int    -- ^ Identifier of the custom emoji with favicon of the website; may be 0 if unknown, in which case the first letter of the domain must be used
    }
  deriving (WebDomainException -> WebDomainException -> Bool
(WebDomainException -> WebDomainException -> Bool)
-> (WebDomainException -> WebDomainException -> Bool)
-> Eq WebDomainException
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WebDomainException -> WebDomainException -> Bool
== :: WebDomainException -> WebDomainException -> Bool
$c/= :: WebDomainException -> WebDomainException -> Bool
/= :: WebDomainException -> WebDomainException -> Bool
Eq, Int -> WebDomainException -> ShowS
[WebDomainException] -> ShowS
WebDomainException -> String
(Int -> WebDomainException -> ShowS)
-> (WebDomainException -> String)
-> ([WebDomainException] -> ShowS)
-> Show WebDomainException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WebDomainException -> ShowS
showsPrec :: Int -> WebDomainException -> ShowS
$cshow :: WebDomainException -> String
show :: WebDomainException -> String
$cshowList :: [WebDomainException] -> ShowS
showList :: [WebDomainException] -> ShowS
Show)

instance I.ShortShow WebDomainException where
  shortShow :: WebDomainException -> String
shortShow WebDomainException
    { url :: WebDomainException -> Maybe Text
url                     = Maybe Text
url_
    , domain :: WebDomainException -> Maybe Text
domain                  = Maybe Text
domain_
    , title :: WebDomainException -> Maybe Text
title                   = Maybe Text
title_
    , favicon_custom_emoji_id :: WebDomainException -> Maybe Int
favicon_custom_emoji_id = Maybe Int
favicon_custom_emoji_id_
    }
      = String
"WebDomainException"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ 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
"title"                   String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , String
"favicon_custom_emoji_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
favicon_custom_emoji_id_
        ]

instance AT.FromJSON WebDomainException where
  parseJSON :: Value -> Parser WebDomainException
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
"webDomainException" -> Value -> Parser WebDomainException
parseWebDomainException Value
v
      String
_                    -> Parser WebDomainException
forall a. Monoid a => a
mempty
    
    where
      parseWebDomainException :: A.Value -> AT.Parser WebDomainException
      parseWebDomainException :: Value -> Parser WebDomainException
parseWebDomainException = String
-> (Object -> Parser WebDomainException)
-> Value
-> Parser WebDomainException
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"WebDomainException" ((Object -> Parser WebDomainException)
 -> Value -> Parser WebDomainException)
-> (Object -> Parser WebDomainException)
-> Value
-> Parser WebDomainException
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        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 Text
title_                   <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"title"
        Maybe Int
favicon_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
"favicon_custom_emoji_id"
        WebDomainException -> Parser WebDomainException
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WebDomainException -> Parser WebDomainException)
-> WebDomainException -> Parser WebDomainException
forall a b. (a -> b) -> a -> b
$ WebDomainException
          { url :: Maybe Text
url                     = Maybe Text
url_
          , domain :: Maybe Text
domain                  = Maybe Text
domain_
          , title :: Maybe Text
title                   = Maybe Text
title_
          , favicon_custom_emoji_id :: Maybe Int
favicon_custom_emoji_id = Maybe Int
favicon_custom_emoji_id_
          }
  parseJSON Value
_ = Parser WebDomainException
forall a. Monoid a => a
mempty