module TD.Data.BusinessStartPage
  (BusinessStartPage(..)) 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.Sticker as Sticker

data BusinessStartPage
  = BusinessStartPage -- ^ Describes settings for a business account start page
    { BusinessStartPage -> Maybe Text
title   :: Maybe T.Text          -- ^ Title text of the start page
    , BusinessStartPage -> Maybe Text
message :: Maybe T.Text          -- ^ Message text of the start page
    , BusinessStartPage -> Maybe Sticker
sticker :: Maybe Sticker.Sticker -- ^ Greeting sticker of the start page; may be null if none
    }
  deriving (BusinessStartPage -> BusinessStartPage -> Bool
(BusinessStartPage -> BusinessStartPage -> Bool)
-> (BusinessStartPage -> BusinessStartPage -> Bool)
-> Eq BusinessStartPage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BusinessStartPage -> BusinessStartPage -> Bool
== :: BusinessStartPage -> BusinessStartPage -> Bool
$c/= :: BusinessStartPage -> BusinessStartPage -> Bool
/= :: BusinessStartPage -> BusinessStartPage -> Bool
Eq, Int -> BusinessStartPage -> ShowS
[BusinessStartPage] -> ShowS
BusinessStartPage -> String
(Int -> BusinessStartPage -> ShowS)
-> (BusinessStartPage -> String)
-> ([BusinessStartPage] -> ShowS)
-> Show BusinessStartPage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BusinessStartPage -> ShowS
showsPrec :: Int -> BusinessStartPage -> ShowS
$cshow :: BusinessStartPage -> String
show :: BusinessStartPage -> String
$cshowList :: [BusinessStartPage] -> ShowS
showList :: [BusinessStartPage] -> ShowS
Show)

instance I.ShortShow BusinessStartPage where
  shortShow :: BusinessStartPage -> String
shortShow BusinessStartPage
    { title :: BusinessStartPage -> Maybe Text
title   = Maybe Text
title_
    , message :: BusinessStartPage -> Maybe Text
message = Maybe Text
message_
    , sticker :: BusinessStartPage -> Maybe Sticker
sticker = Maybe Sticker
sticker_
    }
      = String
"BusinessStartPage"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"title"   String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , String
"message" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
message_
        , String
"sticker" String -> Maybe Sticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Sticker
sticker_
        ]

instance AT.FromJSON BusinessStartPage where
  parseJSON :: Value -> Parser BusinessStartPage
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
"businessStartPage" -> Value -> Parser BusinessStartPage
parseBusinessStartPage Value
v
      String
_                   -> Parser BusinessStartPage
forall a. Monoid a => a
mempty
    
    where
      parseBusinessStartPage :: A.Value -> AT.Parser BusinessStartPage
      parseBusinessStartPage :: Value -> Parser BusinessStartPage
parseBusinessStartPage = String
-> (Object -> Parser BusinessStartPage)
-> Value
-> Parser BusinessStartPage
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BusinessStartPage" ((Object -> Parser BusinessStartPage)
 -> Value -> Parser BusinessStartPage)
-> (Object -> Parser BusinessStartPage)
-> Value
-> Parser BusinessStartPage
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
title_   <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"title"
        Maybe Text
message_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"message"
        Maybe Sticker
sticker_ <- Object
o Object -> Key -> Parser (Maybe Sticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sticker"
        BusinessStartPage -> Parser BusinessStartPage
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BusinessStartPage -> Parser BusinessStartPage)
-> BusinessStartPage -> Parser BusinessStartPage
forall a b. (a -> b) -> a -> b
$ BusinessStartPage
          { title :: Maybe Text
title   = Maybe Text
title_
          , message :: Maybe Text
message = Maybe Text
message_
          , sticker :: Maybe Sticker
sticker = Maybe Sticker
sticker_
          }
  parseJSON Value
_ = Parser BusinessStartPage
forall a. Monoid a => a
mempty