{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}
module Amazonka.AppMesh.Types.Duration where
import Amazonka.AppMesh.Types.DurationUnit
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
data Duration = Duration'
{
Duration -> Maybe Natural
value :: Prelude.Maybe Prelude.Natural,
Duration -> Maybe DurationUnit
unit :: Prelude.Maybe DurationUnit
}
deriving (Duration -> Duration -> Bool
(Duration -> Duration -> Bool)
-> (Duration -> Duration -> Bool) -> Eq Duration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Duration -> Duration -> Bool
$c/= :: Duration -> Duration -> Bool
== :: Duration -> Duration -> Bool
$c== :: Duration -> Duration -> Bool
Prelude.Eq, ReadPrec [Duration]
ReadPrec Duration
Int -> ReadS Duration
ReadS [Duration]
(Int -> ReadS Duration)
-> ReadS [Duration]
-> ReadPrec Duration
-> ReadPrec [Duration]
-> Read Duration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Duration]
$creadListPrec :: ReadPrec [Duration]
readPrec :: ReadPrec Duration
$creadPrec :: ReadPrec Duration
readList :: ReadS [Duration]
$creadList :: ReadS [Duration]
readsPrec :: Int -> ReadS Duration
$creadsPrec :: Int -> ReadS Duration
Prelude.Read, Int -> Duration -> ShowS
[Duration] -> ShowS
Duration -> String
(Int -> Duration -> ShowS)
-> (Duration -> String) -> ([Duration] -> ShowS) -> Show Duration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Duration] -> ShowS
$cshowList :: [Duration] -> ShowS
show :: Duration -> String
$cshow :: Duration -> String
showsPrec :: Int -> Duration -> ShowS
$cshowsPrec :: Int -> Duration -> ShowS
Prelude.Show, (forall x. Duration -> Rep Duration x)
-> (forall x. Rep Duration x -> Duration) -> Generic Duration
forall x. Rep Duration x -> Duration
forall x. Duration -> Rep Duration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Duration x -> Duration
$cfrom :: forall x. Duration -> Rep Duration x
Prelude.Generic)
newDuration ::
Duration
newDuration :: Duration
newDuration =
Duration' :: Maybe Natural -> Maybe DurationUnit -> Duration
Duration'
{ $sel:value:Duration' :: Maybe Natural
value = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
$sel:unit:Duration' :: Maybe DurationUnit
unit = Maybe DurationUnit
forall a. Maybe a
Prelude.Nothing
}
duration_value :: Lens.Lens' Duration (Prelude.Maybe Prelude.Natural)
duration_value :: (Maybe Natural -> f (Maybe Natural)) -> Duration -> f Duration
duration_value = (Duration -> Maybe Natural)
-> (Duration -> Maybe Natural -> Duration)
-> Lens Duration Duration (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Duration' {Maybe Natural
value :: Maybe Natural
$sel:value:Duration' :: Duration -> Maybe Natural
value} -> Maybe Natural
value) (\s :: Duration
s@Duration' {} Maybe Natural
a -> Duration
s {$sel:value:Duration' :: Maybe Natural
value = Maybe Natural
a} :: Duration)
duration_unit :: Lens.Lens' Duration (Prelude.Maybe DurationUnit)
duration_unit :: (Maybe DurationUnit -> f (Maybe DurationUnit))
-> Duration -> f Duration
duration_unit = (Duration -> Maybe DurationUnit)
-> (Duration -> Maybe DurationUnit -> Duration)
-> Lens Duration Duration (Maybe DurationUnit) (Maybe DurationUnit)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Duration' {Maybe DurationUnit
unit :: Maybe DurationUnit
$sel:unit:Duration' :: Duration -> Maybe DurationUnit
unit} -> Maybe DurationUnit
unit) (\s :: Duration
s@Duration' {} Maybe DurationUnit
a -> Duration
s {$sel:unit:Duration' :: Maybe DurationUnit
unit = Maybe DurationUnit
a} :: Duration)
instance Core.FromJSON Duration where
parseJSON :: Value -> Parser Duration
parseJSON =
String -> (Object -> Parser Duration) -> Value -> Parser Duration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
String
"Duration"
( \Object
x ->
Maybe Natural -> Maybe DurationUnit -> Duration
Duration'
(Maybe Natural -> Maybe DurationUnit -> Duration)
-> Parser (Maybe Natural)
-> Parser (Maybe DurationUnit -> Duration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"value") Parser (Maybe DurationUnit -> Duration)
-> Parser (Maybe DurationUnit) -> Parser Duration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe DurationUnit)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"unit")
)
instance Prelude.Hashable Duration
instance Prelude.NFData Duration
instance Core.ToJSON Duration where
toJSON :: Duration -> Value
toJSON Duration' {Maybe Natural
Maybe DurationUnit
unit :: Maybe DurationUnit
value :: Maybe Natural
$sel:unit:Duration' :: Duration -> Maybe DurationUnit
$sel:value:Duration' :: Duration -> Maybe Natural
..} =
[Pair] -> Value
Core.object
( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
[ (Text
"value" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
value,
(Text
"unit" Text -> DurationUnit -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (DurationUnit -> Pair) -> Maybe DurationUnit -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DurationUnit
unit
]
)