module TD.Data.BusinessAwayMessageSchedule
(BusinessAwayMessageSchedule(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data BusinessAwayMessageSchedule
= BusinessAwayMessageScheduleAlways
| BusinessAwayMessageScheduleOutsideOfOpeningHours
| BusinessAwayMessageScheduleCustom
{ BusinessAwayMessageSchedule -> Maybe Int
start_date :: Maybe Int
, BusinessAwayMessageSchedule -> Maybe Int
end_date :: Maybe Int
}
deriving (BusinessAwayMessageSchedule -> BusinessAwayMessageSchedule -> Bool
(BusinessAwayMessageSchedule
-> BusinessAwayMessageSchedule -> Bool)
-> (BusinessAwayMessageSchedule
-> BusinessAwayMessageSchedule -> Bool)
-> Eq BusinessAwayMessageSchedule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BusinessAwayMessageSchedule -> BusinessAwayMessageSchedule -> Bool
== :: BusinessAwayMessageSchedule -> BusinessAwayMessageSchedule -> Bool
$c/= :: BusinessAwayMessageSchedule -> BusinessAwayMessageSchedule -> Bool
/= :: BusinessAwayMessageSchedule -> BusinessAwayMessageSchedule -> Bool
Eq, Int -> BusinessAwayMessageSchedule -> ShowS
[BusinessAwayMessageSchedule] -> ShowS
BusinessAwayMessageSchedule -> String
(Int -> BusinessAwayMessageSchedule -> ShowS)
-> (BusinessAwayMessageSchedule -> String)
-> ([BusinessAwayMessageSchedule] -> ShowS)
-> Show BusinessAwayMessageSchedule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BusinessAwayMessageSchedule -> ShowS
showsPrec :: Int -> BusinessAwayMessageSchedule -> ShowS
$cshow :: BusinessAwayMessageSchedule -> String
show :: BusinessAwayMessageSchedule -> String
$cshowList :: [BusinessAwayMessageSchedule] -> ShowS
showList :: [BusinessAwayMessageSchedule] -> ShowS
Show)
instance I.ShortShow BusinessAwayMessageSchedule where
shortShow :: BusinessAwayMessageSchedule -> String
shortShow BusinessAwayMessageSchedule
BusinessAwayMessageScheduleAlways
= String
"BusinessAwayMessageScheduleAlways"
shortShow BusinessAwayMessageSchedule
BusinessAwayMessageScheduleOutsideOfOpeningHours
= String
"BusinessAwayMessageScheduleOutsideOfOpeningHours"
shortShow BusinessAwayMessageScheduleCustom
{ start_date :: BusinessAwayMessageSchedule -> Maybe Int
start_date = Maybe Int
start_date_
, end_date :: BusinessAwayMessageSchedule -> Maybe Int
end_date = Maybe Int
end_date_
}
= String
"BusinessAwayMessageScheduleCustom"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"start_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
start_date_
, String
"end_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
end_date_
]
instance AT.FromJSON BusinessAwayMessageSchedule where
parseJSON :: Value -> Parser BusinessAwayMessageSchedule
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
"businessAwayMessageScheduleAlways" -> BusinessAwayMessageSchedule -> Parser BusinessAwayMessageSchedule
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BusinessAwayMessageSchedule
BusinessAwayMessageScheduleAlways
String
"businessAwayMessageScheduleOutsideOfOpeningHours" -> BusinessAwayMessageSchedule -> Parser BusinessAwayMessageSchedule
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BusinessAwayMessageSchedule
BusinessAwayMessageScheduleOutsideOfOpeningHours
String
"businessAwayMessageScheduleCustom" -> Value -> Parser BusinessAwayMessageSchedule
parseBusinessAwayMessageScheduleCustom Value
v
String
_ -> Parser BusinessAwayMessageSchedule
forall a. Monoid a => a
mempty
where
parseBusinessAwayMessageScheduleCustom :: A.Value -> AT.Parser BusinessAwayMessageSchedule
parseBusinessAwayMessageScheduleCustom :: Value -> Parser BusinessAwayMessageSchedule
parseBusinessAwayMessageScheduleCustom = String
-> (Object -> Parser BusinessAwayMessageSchedule)
-> Value
-> Parser BusinessAwayMessageSchedule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BusinessAwayMessageScheduleCustom" ((Object -> Parser BusinessAwayMessageSchedule)
-> Value -> Parser BusinessAwayMessageSchedule)
-> (Object -> Parser BusinessAwayMessageSchedule)
-> Value
-> Parser BusinessAwayMessageSchedule
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
start_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"start_date"
Maybe Int
end_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"end_date"
BusinessAwayMessageSchedule -> Parser BusinessAwayMessageSchedule
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BusinessAwayMessageSchedule -> Parser BusinessAwayMessageSchedule)
-> BusinessAwayMessageSchedule
-> Parser BusinessAwayMessageSchedule
forall a b. (a -> b) -> a -> b
$ BusinessAwayMessageScheduleCustom
{ start_date :: Maybe Int
start_date = Maybe Int
start_date_
, end_date :: Maybe Int
end_date = Maybe Int
end_date_
}
parseJSON Value
_ = Parser BusinessAwayMessageSchedule
forall a. Monoid a => a
mempty
instance AT.ToJSON BusinessAwayMessageSchedule where
toJSON :: BusinessAwayMessageSchedule -> Value
toJSON BusinessAwayMessageSchedule
BusinessAwayMessageScheduleAlways
= [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
"businessAwayMessageScheduleAlways"
]
toJSON BusinessAwayMessageSchedule
BusinessAwayMessageScheduleOutsideOfOpeningHours
= [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
"businessAwayMessageScheduleOutsideOfOpeningHours"
]
toJSON BusinessAwayMessageScheduleCustom
{ start_date :: BusinessAwayMessageSchedule -> Maybe Int
start_date = Maybe Int
start_date_
, end_date :: BusinessAwayMessageSchedule -> Maybe Int
end_date = Maybe Int
end_date_
}
= [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
"businessAwayMessageScheduleCustom"
, Key
"start_date" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
start_date_
, Key
"end_date" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
end_date_
]