module TD.Data.BusinessOpeningHoursInterval
( BusinessOpeningHoursInterval(..)
, defaultBusinessOpeningHoursInterval
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data BusinessOpeningHoursInterval
= BusinessOpeningHoursInterval
{ BusinessOpeningHoursInterval -> Maybe Int
start_minute :: Maybe Int
, BusinessOpeningHoursInterval -> Maybe Int
end_minute :: Maybe Int
}
deriving (BusinessOpeningHoursInterval
-> BusinessOpeningHoursInterval -> Bool
(BusinessOpeningHoursInterval
-> BusinessOpeningHoursInterval -> Bool)
-> (BusinessOpeningHoursInterval
-> BusinessOpeningHoursInterval -> Bool)
-> Eq BusinessOpeningHoursInterval
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BusinessOpeningHoursInterval
-> BusinessOpeningHoursInterval -> Bool
== :: BusinessOpeningHoursInterval
-> BusinessOpeningHoursInterval -> Bool
$c/= :: BusinessOpeningHoursInterval
-> BusinessOpeningHoursInterval -> Bool
/= :: BusinessOpeningHoursInterval
-> BusinessOpeningHoursInterval -> Bool
Eq, Int -> BusinessOpeningHoursInterval -> ShowS
[BusinessOpeningHoursInterval] -> ShowS
BusinessOpeningHoursInterval -> String
(Int -> BusinessOpeningHoursInterval -> ShowS)
-> (BusinessOpeningHoursInterval -> String)
-> ([BusinessOpeningHoursInterval] -> ShowS)
-> Show BusinessOpeningHoursInterval
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BusinessOpeningHoursInterval -> ShowS
showsPrec :: Int -> BusinessOpeningHoursInterval -> ShowS
$cshow :: BusinessOpeningHoursInterval -> String
show :: BusinessOpeningHoursInterval -> String
$cshowList :: [BusinessOpeningHoursInterval] -> ShowS
showList :: [BusinessOpeningHoursInterval] -> ShowS
Show)
instance I.ShortShow BusinessOpeningHoursInterval where
shortShow :: BusinessOpeningHoursInterval -> String
shortShow BusinessOpeningHoursInterval
{ start_minute :: BusinessOpeningHoursInterval -> Maybe Int
start_minute = Maybe Int
start_minute_
, end_minute :: BusinessOpeningHoursInterval -> Maybe Int
end_minute = Maybe Int
end_minute_
}
= String
"BusinessOpeningHoursInterval"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"start_minute" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
start_minute_
, String
"end_minute" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
end_minute_
]
instance AT.FromJSON BusinessOpeningHoursInterval where
parseJSON :: Value -> Parser BusinessOpeningHoursInterval
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
"businessOpeningHoursInterval" -> Value -> Parser BusinessOpeningHoursInterval
parseBusinessOpeningHoursInterval Value
v
String
_ -> Parser BusinessOpeningHoursInterval
forall a. Monoid a => a
mempty
where
parseBusinessOpeningHoursInterval :: A.Value -> AT.Parser BusinessOpeningHoursInterval
parseBusinessOpeningHoursInterval :: Value -> Parser BusinessOpeningHoursInterval
parseBusinessOpeningHoursInterval = String
-> (Object -> Parser BusinessOpeningHoursInterval)
-> Value
-> Parser BusinessOpeningHoursInterval
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BusinessOpeningHoursInterval" ((Object -> Parser BusinessOpeningHoursInterval)
-> Value -> Parser BusinessOpeningHoursInterval)
-> (Object -> Parser BusinessOpeningHoursInterval)
-> Value
-> Parser BusinessOpeningHoursInterval
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
start_minute_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"start_minute"
Maybe Int
end_minute_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"end_minute"
BusinessOpeningHoursInterval -> Parser BusinessOpeningHoursInterval
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BusinessOpeningHoursInterval
-> Parser BusinessOpeningHoursInterval)
-> BusinessOpeningHoursInterval
-> Parser BusinessOpeningHoursInterval
forall a b. (a -> b) -> a -> b
$ BusinessOpeningHoursInterval
{ start_minute :: Maybe Int
start_minute = Maybe Int
start_minute_
, end_minute :: Maybe Int
end_minute = Maybe Int
end_minute_
}
parseJSON Value
_ = Parser BusinessOpeningHoursInterval
forall a. Monoid a => a
mempty
instance AT.ToJSON BusinessOpeningHoursInterval where
toJSON :: BusinessOpeningHoursInterval -> Value
toJSON BusinessOpeningHoursInterval
{ start_minute :: BusinessOpeningHoursInterval -> Maybe Int
start_minute = Maybe Int
start_minute_
, end_minute :: BusinessOpeningHoursInterval -> Maybe Int
end_minute = Maybe Int
end_minute_
}
= [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
"businessOpeningHoursInterval"
, Key
"start_minute" 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_minute_
, Key
"end_minute" 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_minute_
]
defaultBusinessOpeningHoursInterval :: BusinessOpeningHoursInterval
defaultBusinessOpeningHoursInterval :: BusinessOpeningHoursInterval
defaultBusinessOpeningHoursInterval =
BusinessOpeningHoursInterval
{ start_minute :: Maybe Int
start_minute = Maybe Int
forall a. Maybe a
Nothing
, end_minute :: Maybe Int
end_minute = Maybe Int
forall a. Maybe a
Nothing
}