module TD.Data.WebApp
  (WebApp(..)) 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
import qualified TD.Data.Photo as Photo
import qualified TD.Data.Animation as Animation

data WebApp
  = WebApp -- ^ Describes a Web App. Use getInternalLink with internalLinkTypeWebApp to share the Web App
    { WebApp -> Maybe Text
short_name  :: Maybe T.Text              -- ^ Web App short name
    , WebApp -> Maybe Text
title       :: Maybe T.Text              -- ^ Web App title
    , WebApp -> Maybe Text
description :: Maybe T.Text              -- ^ Web App description
    , WebApp -> Maybe Photo
photo       :: Maybe Photo.Photo         -- ^ Web App photo
    , WebApp -> Maybe Animation
animation   :: Maybe Animation.Animation -- ^ Web App animation; may be null
    }
  deriving (WebApp -> WebApp -> Bool
(WebApp -> WebApp -> Bool)
-> (WebApp -> WebApp -> Bool) -> Eq WebApp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WebApp -> WebApp -> Bool
== :: WebApp -> WebApp -> Bool
$c/= :: WebApp -> WebApp -> Bool
/= :: WebApp -> WebApp -> Bool
Eq, Int -> WebApp -> ShowS
[WebApp] -> ShowS
WebApp -> String
(Int -> WebApp -> ShowS)
-> (WebApp -> String) -> ([WebApp] -> ShowS) -> Show WebApp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WebApp -> ShowS
showsPrec :: Int -> WebApp -> ShowS
$cshow :: WebApp -> String
show :: WebApp -> String
$cshowList :: [WebApp] -> ShowS
showList :: [WebApp] -> ShowS
Show)

instance I.ShortShow WebApp where
  shortShow :: WebApp -> String
shortShow WebApp
    { short_name :: WebApp -> Maybe Text
short_name  = Maybe Text
short_name_
    , title :: WebApp -> Maybe Text
title       = Maybe Text
title_
    , description :: WebApp -> Maybe Text
description = Maybe Text
description_
    , photo :: WebApp -> Maybe Photo
photo       = Maybe Photo
photo_
    , animation :: WebApp -> Maybe Animation
animation   = Maybe Animation
animation_
    }
      = String
"WebApp"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"short_name"  String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
short_name_
        , String
"title"       String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , String
"description" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
description_
        , String
"photo"       String -> Maybe Photo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Photo
photo_
        , String
"animation"   String -> Maybe Animation -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Animation
animation_
        ]

instance AT.FromJSON WebApp where
  parseJSON :: Value -> Parser WebApp
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
"webApp" -> Value -> Parser WebApp
parseWebApp Value
v
      String
_        -> Parser WebApp
forall a. Monoid a => a
mempty
    
    where
      parseWebApp :: A.Value -> AT.Parser WebApp
      parseWebApp :: Value -> Parser WebApp
parseWebApp = String -> (Object -> Parser WebApp) -> Value -> Parser WebApp
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"WebApp" ((Object -> Parser WebApp) -> Value -> Parser WebApp)
-> (Object -> Parser WebApp) -> Value -> Parser WebApp
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
short_name_  <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"short_name"
        Maybe Text
title_       <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"title"
        Maybe Text
description_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"description"
        Maybe Photo
photo_       <- Object
o Object -> Key -> Parser (Maybe Photo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"photo"
        Maybe Animation
animation_   <- Object
o Object -> Key -> Parser (Maybe Animation)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"animation"
        WebApp -> Parser WebApp
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WebApp -> Parser WebApp) -> WebApp -> Parser WebApp
forall a b. (a -> b) -> a -> b
$ WebApp
          { short_name :: Maybe Text
short_name  = Maybe Text
short_name_
          , title :: Maybe Text
title       = Maybe Text
title_
          , description :: Maybe Text
description = Maybe Text
description_
          , photo :: Maybe Photo
photo       = Maybe Photo
photo_
          , animation :: Maybe Animation
animation   = Maybe Animation
animation_
          }
  parseJSON Value
_ = Parser WebApp
forall a. Monoid a => a
mempty