module TD.Data.MainWebApp
  (MainWebApp(..)) 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 MainWebApp
  = MainWebApp -- ^ Contains information about the main Web App of a bot
    { MainWebApp -> Maybe Text
url        :: Maybe T.Text -- ^ URL of the Web App to open
    , MainWebApp -> Maybe Bool
is_compact :: Maybe Bool   -- ^ True, if the Web App must always be opened in the compact mode instead of the full-size mode
    }
  deriving (MainWebApp -> MainWebApp -> Bool
(MainWebApp -> MainWebApp -> Bool)
-> (MainWebApp -> MainWebApp -> Bool) -> Eq MainWebApp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MainWebApp -> MainWebApp -> Bool
== :: MainWebApp -> MainWebApp -> Bool
$c/= :: MainWebApp -> MainWebApp -> Bool
/= :: MainWebApp -> MainWebApp -> Bool
Eq, Int -> MainWebApp -> ShowS
[MainWebApp] -> ShowS
MainWebApp -> String
(Int -> MainWebApp -> ShowS)
-> (MainWebApp -> String)
-> ([MainWebApp] -> ShowS)
-> Show MainWebApp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MainWebApp -> ShowS
showsPrec :: Int -> MainWebApp -> ShowS
$cshow :: MainWebApp -> String
show :: MainWebApp -> String
$cshowList :: [MainWebApp] -> ShowS
showList :: [MainWebApp] -> ShowS
Show)

instance I.ShortShow MainWebApp where
  shortShow :: MainWebApp -> String
shortShow MainWebApp
    { url :: MainWebApp -> Maybe Text
url        = Maybe Text
url_
    , is_compact :: MainWebApp -> Maybe Bool
is_compact = Maybe Bool
is_compact_
    }
      = String
"MainWebApp"
        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
"is_compact" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_compact_
        ]

instance AT.FromJSON MainWebApp where
  parseJSON :: Value -> Parser MainWebApp
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
"mainWebApp" -> Value -> Parser MainWebApp
parseMainWebApp Value
v
      String
_            -> Parser MainWebApp
forall a. Monoid a => a
mempty
    
    where
      parseMainWebApp :: A.Value -> AT.Parser MainWebApp
      parseMainWebApp :: Value -> Parser MainWebApp
parseMainWebApp = String
-> (Object -> Parser MainWebApp) -> Value -> Parser MainWebApp
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MainWebApp" ((Object -> Parser MainWebApp) -> Value -> Parser MainWebApp)
-> (Object -> Parser MainWebApp) -> Value -> Parser MainWebApp
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 Bool
is_compact_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_compact"
        MainWebApp -> Parser MainWebApp
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MainWebApp -> Parser MainWebApp)
-> MainWebApp -> Parser MainWebApp
forall a b. (a -> b) -> a -> b
$ MainWebApp
          { url :: Maybe Text
url        = Maybe Text
url_
          , is_compact :: Maybe Bool
is_compact = Maybe Bool
is_compact_
          }
  parseJSON Value
_ = Parser MainWebApp
forall a. Monoid a => a
mempty