module TD.Data.BusinessAwayMessageSettings
( BusinessAwayMessageSettings(..)
, defaultBusinessAwayMessageSettings
) 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
import qualified TD.Data.BusinessAwayMessageSchedule as BusinessAwayMessageSchedule
data BusinessAwayMessageSettings
= BusinessAwayMessageSettings
{ BusinessAwayMessageSettings -> Maybe Int
shortcut_id :: Maybe Int
, BusinessAwayMessageSettings -> Maybe BusinessRecipients
recipients :: Maybe BusinessRecipients.BusinessRecipients
, BusinessAwayMessageSettings -> Maybe BusinessAwayMessageSchedule
schedule :: Maybe BusinessAwayMessageSchedule.BusinessAwayMessageSchedule
, BusinessAwayMessageSettings -> Maybe Bool
offline_only :: Maybe Bool
}
deriving (BusinessAwayMessageSettings -> BusinessAwayMessageSettings -> Bool
(BusinessAwayMessageSettings
-> BusinessAwayMessageSettings -> Bool)
-> (BusinessAwayMessageSettings
-> BusinessAwayMessageSettings -> Bool)
-> Eq BusinessAwayMessageSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BusinessAwayMessageSettings -> BusinessAwayMessageSettings -> Bool
== :: BusinessAwayMessageSettings -> BusinessAwayMessageSettings -> Bool
$c/= :: BusinessAwayMessageSettings -> BusinessAwayMessageSettings -> Bool
/= :: BusinessAwayMessageSettings -> BusinessAwayMessageSettings -> Bool
Eq, Int -> BusinessAwayMessageSettings -> ShowS
[BusinessAwayMessageSettings] -> ShowS
BusinessAwayMessageSettings -> String
(Int -> BusinessAwayMessageSettings -> ShowS)
-> (BusinessAwayMessageSettings -> String)
-> ([BusinessAwayMessageSettings] -> ShowS)
-> Show BusinessAwayMessageSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BusinessAwayMessageSettings -> ShowS
showsPrec :: Int -> BusinessAwayMessageSettings -> ShowS
$cshow :: BusinessAwayMessageSettings -> String
show :: BusinessAwayMessageSettings -> String
$cshowList :: [BusinessAwayMessageSettings] -> ShowS
showList :: [BusinessAwayMessageSettings] -> ShowS
Show)
instance I.ShortShow BusinessAwayMessageSettings where
shortShow :: BusinessAwayMessageSettings -> String
shortShow BusinessAwayMessageSettings
{ shortcut_id :: BusinessAwayMessageSettings -> Maybe Int
shortcut_id = Maybe Int
shortcut_id_
, recipients :: BusinessAwayMessageSettings -> Maybe BusinessRecipients
recipients = Maybe BusinessRecipients
recipients_
, schedule :: BusinessAwayMessageSettings -> Maybe BusinessAwayMessageSchedule
schedule = Maybe BusinessAwayMessageSchedule
schedule_
, offline_only :: BusinessAwayMessageSettings -> Maybe Bool
offline_only = Maybe Bool
offline_only_
}
= String
"BusinessAwayMessageSettings"
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
"schedule" String -> Maybe BusinessAwayMessageSchedule -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe BusinessAwayMessageSchedule
schedule_
, String
"offline_only" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
offline_only_
]
instance AT.FromJSON BusinessAwayMessageSettings where
parseJSON :: Value -> Parser BusinessAwayMessageSettings
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
"businessAwayMessageSettings" -> Value -> Parser BusinessAwayMessageSettings
parseBusinessAwayMessageSettings Value
v
String
_ -> Parser BusinessAwayMessageSettings
forall a. Monoid a => a
mempty
where
parseBusinessAwayMessageSettings :: A.Value -> AT.Parser BusinessAwayMessageSettings
parseBusinessAwayMessageSettings :: Value -> Parser BusinessAwayMessageSettings
parseBusinessAwayMessageSettings = String
-> (Object -> Parser BusinessAwayMessageSettings)
-> Value
-> Parser BusinessAwayMessageSettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BusinessAwayMessageSettings" ((Object -> Parser BusinessAwayMessageSettings)
-> Value -> Parser BusinessAwayMessageSettings)
-> (Object -> Parser BusinessAwayMessageSettings)
-> Value
-> Parser BusinessAwayMessageSettings
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 BusinessAwayMessageSchedule
schedule_ <- Object
o Object -> Key -> Parser (Maybe BusinessAwayMessageSchedule)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"schedule"
Maybe Bool
offline_only_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"offline_only"
BusinessAwayMessageSettings -> Parser BusinessAwayMessageSettings
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BusinessAwayMessageSettings -> Parser BusinessAwayMessageSettings)
-> BusinessAwayMessageSettings
-> Parser BusinessAwayMessageSettings
forall a b. (a -> b) -> a -> b
$ BusinessAwayMessageSettings
{ shortcut_id :: Maybe Int
shortcut_id = Maybe Int
shortcut_id_
, recipients :: Maybe BusinessRecipients
recipients = Maybe BusinessRecipients
recipients_
, schedule :: Maybe BusinessAwayMessageSchedule
schedule = Maybe BusinessAwayMessageSchedule
schedule_
, offline_only :: Maybe Bool
offline_only = Maybe Bool
offline_only_
}
parseJSON Value
_ = Parser BusinessAwayMessageSettings
forall a. Monoid a => a
mempty
instance AT.ToJSON BusinessAwayMessageSettings where
toJSON :: BusinessAwayMessageSettings -> Value
toJSON BusinessAwayMessageSettings
{ shortcut_id :: BusinessAwayMessageSettings -> Maybe Int
shortcut_id = Maybe Int
shortcut_id_
, recipients :: BusinessAwayMessageSettings -> Maybe BusinessRecipients
recipients = Maybe BusinessRecipients
recipients_
, schedule :: BusinessAwayMessageSettings -> Maybe BusinessAwayMessageSchedule
schedule = Maybe BusinessAwayMessageSchedule
schedule_
, offline_only :: BusinessAwayMessageSettings -> Maybe Bool
offline_only = Maybe Bool
offline_only_
}
= [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
"businessAwayMessageSettings"
, 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
"schedule" Key -> Maybe BusinessAwayMessageSchedule -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe BusinessAwayMessageSchedule
schedule_
, Key
"offline_only" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
offline_only_
]
defaultBusinessAwayMessageSettings :: BusinessAwayMessageSettings
defaultBusinessAwayMessageSettings :: BusinessAwayMessageSettings
defaultBusinessAwayMessageSettings =
BusinessAwayMessageSettings
{ shortcut_id :: Maybe Int
shortcut_id = Maybe Int
forall a. Maybe a
Nothing
, recipients :: Maybe BusinessRecipients
recipients = Maybe BusinessRecipients
forall a. Maybe a
Nothing
, schedule :: Maybe BusinessAwayMessageSchedule
schedule = Maybe BusinessAwayMessageSchedule
forall a. Maybe a
Nothing
, offline_only :: Maybe Bool
offline_only = Maybe Bool
forall a. Maybe a
Nothing
}