module TD.Data.BusinessGreetingMessageSettings
  ( BusinessGreetingMessageSettings(..)    
  , defaultBusinessGreetingMessageSettings 
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.BusinessRecipients as BusinessRecipients

data BusinessGreetingMessageSettings
  = BusinessGreetingMessageSettings -- ^ Describes settings for greeting messages that are automatically sent by a Telegram Business account as response to incoming messages in an inactive private chat
    { BusinessGreetingMessageSettings -> Maybe Int
shortcut_id     :: Maybe Int                                   -- ^ Unique quick reply shortcut identifier for the greeting messages
    , BusinessGreetingMessageSettings -> Maybe BusinessRecipients
recipients      :: Maybe BusinessRecipients.BusinessRecipients -- ^ Chosen recipients of the greeting messages
    , BusinessGreetingMessageSettings -> Maybe Int
inactivity_days :: Maybe Int                                   -- ^ The number of days after which a chat will be considered as inactive; currently, must be on of 7, 14, 21, or 28
    }
  deriving (BusinessGreetingMessageSettings
-> BusinessGreetingMessageSettings -> Bool
(BusinessGreetingMessageSettings
 -> BusinessGreetingMessageSettings -> Bool)
-> (BusinessGreetingMessageSettings
    -> BusinessGreetingMessageSettings -> Bool)
-> Eq BusinessGreetingMessageSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BusinessGreetingMessageSettings
-> BusinessGreetingMessageSettings -> Bool
== :: BusinessGreetingMessageSettings
-> BusinessGreetingMessageSettings -> Bool
$c/= :: BusinessGreetingMessageSettings
-> BusinessGreetingMessageSettings -> Bool
/= :: BusinessGreetingMessageSettings
-> BusinessGreetingMessageSettings -> Bool
Eq, Int -> BusinessGreetingMessageSettings -> ShowS
[BusinessGreetingMessageSettings] -> ShowS
BusinessGreetingMessageSettings -> String
(Int -> BusinessGreetingMessageSettings -> ShowS)
-> (BusinessGreetingMessageSettings -> String)
-> ([BusinessGreetingMessageSettings] -> ShowS)
-> Show BusinessGreetingMessageSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BusinessGreetingMessageSettings -> ShowS
showsPrec :: Int -> BusinessGreetingMessageSettings -> ShowS
$cshow :: BusinessGreetingMessageSettings -> String
show :: BusinessGreetingMessageSettings -> String
$cshowList :: [BusinessGreetingMessageSettings] -> ShowS
showList :: [BusinessGreetingMessageSettings] -> ShowS
Show)

instance I.ShortShow BusinessGreetingMessageSettings where
  shortShow :: BusinessGreetingMessageSettings -> String
shortShow BusinessGreetingMessageSettings
    { shortcut_id :: BusinessGreetingMessageSettings -> Maybe Int
shortcut_id     = Maybe Int
shortcut_id_
    , recipients :: BusinessGreetingMessageSettings -> Maybe BusinessRecipients
recipients      = Maybe BusinessRecipients
recipients_
    , inactivity_days :: BusinessGreetingMessageSettings -> Maybe Int
inactivity_days = Maybe Int
inactivity_days_
    }
      = String
"BusinessGreetingMessageSettings"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"shortcut_id"     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
shortcut_id_
        , String
"recipients"      String -> Maybe BusinessRecipients -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe BusinessRecipients
recipients_
        , String
"inactivity_days" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
inactivity_days_
        ]

instance AT.FromJSON BusinessGreetingMessageSettings where
  parseJSON :: Value -> Parser BusinessGreetingMessageSettings
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
"businessGreetingMessageSettings" -> Value -> Parser BusinessGreetingMessageSettings
parseBusinessGreetingMessageSettings Value
v
      String
_                                 -> Parser BusinessGreetingMessageSettings
forall a. Monoid a => a
mempty
    
    where
      parseBusinessGreetingMessageSettings :: A.Value -> AT.Parser BusinessGreetingMessageSettings
      parseBusinessGreetingMessageSettings :: Value -> Parser BusinessGreetingMessageSettings
parseBusinessGreetingMessageSettings = String
-> (Object -> Parser BusinessGreetingMessageSettings)
-> Value
-> Parser BusinessGreetingMessageSettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BusinessGreetingMessageSettings" ((Object -> Parser BusinessGreetingMessageSettings)
 -> Value -> Parser BusinessGreetingMessageSettings)
-> (Object -> Parser BusinessGreetingMessageSettings)
-> Value
-> Parser BusinessGreetingMessageSettings
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
shortcut_id_     <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"shortcut_id"
        Maybe BusinessRecipients
recipients_      <- Object
o Object -> Key -> Parser (Maybe BusinessRecipients)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"recipients"
        Maybe Int
inactivity_days_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"inactivity_days"
        BusinessGreetingMessageSettings
-> Parser BusinessGreetingMessageSettings
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BusinessGreetingMessageSettings
 -> Parser BusinessGreetingMessageSettings)
-> BusinessGreetingMessageSettings
-> Parser BusinessGreetingMessageSettings
forall a b. (a -> b) -> a -> b
$ BusinessGreetingMessageSettings
          { shortcut_id :: Maybe Int
shortcut_id     = Maybe Int
shortcut_id_
          , recipients :: Maybe BusinessRecipients
recipients      = Maybe BusinessRecipients
recipients_
          , inactivity_days :: Maybe Int
inactivity_days = Maybe Int
inactivity_days_
          }
  parseJSON Value
_ = Parser BusinessGreetingMessageSettings
forall a. Monoid a => a
mempty

instance AT.ToJSON BusinessGreetingMessageSettings where
  toJSON :: BusinessGreetingMessageSettings -> Value
toJSON BusinessGreetingMessageSettings
    { shortcut_id :: BusinessGreetingMessageSettings -> Maybe Int
shortcut_id     = Maybe Int
shortcut_id_
    , recipients :: BusinessGreetingMessageSettings -> Maybe BusinessRecipients
recipients      = Maybe BusinessRecipients
recipients_
    , inactivity_days :: BusinessGreetingMessageSettings -> Maybe Int
inactivity_days = Maybe Int
inactivity_days_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"           Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"businessGreetingMessageSettings"
        , Key
"shortcut_id"     Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
shortcut_id_
        , Key
"recipients"      Key -> Maybe BusinessRecipients -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe BusinessRecipients
recipients_
        , Key
"inactivity_days" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
inactivity_days_
        ]

defaultBusinessGreetingMessageSettings :: BusinessGreetingMessageSettings
defaultBusinessGreetingMessageSettings :: BusinessGreetingMessageSettings
defaultBusinessGreetingMessageSettings =
  BusinessGreetingMessageSettings
    { shortcut_id :: Maybe Int
shortcut_id     = Maybe Int
forall a. Maybe a
Nothing
    , recipients :: Maybe BusinessRecipients
recipients      = Maybe BusinessRecipients
forall a. Maybe a
Nothing
    , inactivity_days :: Maybe Int
inactivity_days = Maybe Int
forall a. Maybe a
Nothing
    }