module TD.Data.QuickReplyShortcut
  (QuickReplyShortcut(..)) 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.QuickReplyMessage as QuickReplyMessage

data QuickReplyShortcut
  = QuickReplyShortcut -- ^ Describes a shortcut that can be used for a quick reply
    { QuickReplyShortcut -> Maybe Int
_id           :: Maybe Int                                 -- ^ Unique shortcut identifier
    , QuickReplyShortcut -> Maybe Text
name          :: Maybe T.Text                              -- ^ The name of the shortcut that can be used to use the shortcut
    , QuickReplyShortcut -> Maybe QuickReplyMessage
first_message :: Maybe QuickReplyMessage.QuickReplyMessage -- ^ The first shortcut message
    , QuickReplyShortcut -> Maybe Int
message_count :: Maybe Int                                 -- ^ The total number of messages in the shortcut
    }
  deriving (QuickReplyShortcut -> QuickReplyShortcut -> Bool
(QuickReplyShortcut -> QuickReplyShortcut -> Bool)
-> (QuickReplyShortcut -> QuickReplyShortcut -> Bool)
-> Eq QuickReplyShortcut
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: QuickReplyShortcut -> QuickReplyShortcut -> Bool
== :: QuickReplyShortcut -> QuickReplyShortcut -> Bool
$c/= :: QuickReplyShortcut -> QuickReplyShortcut -> Bool
/= :: QuickReplyShortcut -> QuickReplyShortcut -> Bool
Eq, Int -> QuickReplyShortcut -> ShowS
[QuickReplyShortcut] -> ShowS
QuickReplyShortcut -> String
(Int -> QuickReplyShortcut -> ShowS)
-> (QuickReplyShortcut -> String)
-> ([QuickReplyShortcut] -> ShowS)
-> Show QuickReplyShortcut
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> QuickReplyShortcut -> ShowS
showsPrec :: Int -> QuickReplyShortcut -> ShowS
$cshow :: QuickReplyShortcut -> String
show :: QuickReplyShortcut -> String
$cshowList :: [QuickReplyShortcut] -> ShowS
showList :: [QuickReplyShortcut] -> ShowS
Show)

instance I.ShortShow QuickReplyShortcut where
  shortShow :: QuickReplyShortcut -> String
shortShow QuickReplyShortcut
    { _id :: QuickReplyShortcut -> Maybe Int
_id           = Maybe Int
_id_
    , name :: QuickReplyShortcut -> Maybe Text
name          = Maybe Text
name_
    , first_message :: QuickReplyShortcut -> Maybe QuickReplyMessage
first_message = Maybe QuickReplyMessage
first_message_
    , message_count :: QuickReplyShortcut -> Maybe Int
message_count = Maybe Int
message_count_
    }
      = String
"QuickReplyShortcut"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_id"           String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
        , String
"name"          String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
        , String
"first_message" String -> Maybe QuickReplyMessage -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe QuickReplyMessage
first_message_
        , String
"message_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_count_
        ]

instance AT.FromJSON QuickReplyShortcut where
  parseJSON :: Value -> Parser QuickReplyShortcut
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
"quickReplyShortcut" -> Value -> Parser QuickReplyShortcut
parseQuickReplyShortcut Value
v
      String
_                    -> Parser QuickReplyShortcut
forall a. Monoid a => a
mempty
    
    where
      parseQuickReplyShortcut :: A.Value -> AT.Parser QuickReplyShortcut
      parseQuickReplyShortcut :: Value -> Parser QuickReplyShortcut
parseQuickReplyShortcut = String
-> (Object -> Parser QuickReplyShortcut)
-> Value
-> Parser QuickReplyShortcut
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"QuickReplyShortcut" ((Object -> Parser QuickReplyShortcut)
 -> Value -> Parser QuickReplyShortcut)
-> (Object -> Parser QuickReplyShortcut)
-> Value
-> Parser QuickReplyShortcut
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
_id_           <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"id"
        Maybe Text
name_          <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"name"
        Maybe QuickReplyMessage
first_message_ <- Object
o Object -> Key -> Parser (Maybe QuickReplyMessage)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"first_message"
        Maybe Int
message_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"message_count"
        QuickReplyShortcut -> Parser QuickReplyShortcut
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (QuickReplyShortcut -> Parser QuickReplyShortcut)
-> QuickReplyShortcut -> Parser QuickReplyShortcut
forall a b. (a -> b) -> a -> b
$ QuickReplyShortcut
          { _id :: Maybe Int
_id           = Maybe Int
_id_
          , name :: Maybe Text
name          = Maybe Text
name_
          , first_message :: Maybe QuickReplyMessage
first_message = Maybe QuickReplyMessage
first_message_
          , message_count :: Maybe Int
message_count = Maybe Int
message_count_
          }
  parseJSON Value
_ = Parser QuickReplyShortcut
forall a. Monoid a => a
mempty