{-# 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.OpenSearch.Types.Duration where
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.OpenSearch.Types.TimeUnit
import qualified Amazonka.Prelude as Prelude
data Duration = Duration'
{
Duration -> Maybe Natural
value :: Prelude.Maybe Prelude.Natural,
Duration -> Maybe TimeUnit
unit :: Prelude.Maybe TimeUnit
}
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 TimeUnit -> Duration
Duration'
{ $sel:value:Duration' :: Maybe Natural
value = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
$sel:unit:Duration' :: Maybe TimeUnit
unit = Maybe TimeUnit
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 TimeUnit)
duration_unit :: (Maybe TimeUnit -> f (Maybe TimeUnit)) -> Duration -> f Duration
duration_unit = (Duration -> Maybe TimeUnit)
-> (Duration -> Maybe TimeUnit -> Duration)
-> Lens Duration Duration (Maybe TimeUnit) (Maybe TimeUnit)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Duration' {Maybe TimeUnit
unit :: Maybe TimeUnit
$sel:unit:Duration' :: Duration -> Maybe TimeUnit
unit} -> Maybe TimeUnit
unit) (\s :: Duration
s@Duration' {} Maybe TimeUnit
a -> Duration
s {$sel:unit:Duration' :: Maybe TimeUnit
unit = Maybe TimeUnit
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 TimeUnit -> Duration
Duration'
(Maybe Natural -> Maybe TimeUnit -> Duration)
-> Parser (Maybe Natural) -> Parser (Maybe TimeUnit -> 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 TimeUnit -> Duration)
-> Parser (Maybe TimeUnit) -> Parser Duration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe TimeUnit)
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 TimeUnit
unit :: Maybe TimeUnit
value :: Maybe Natural
$sel:unit:Duration' :: Duration -> Maybe TimeUnit
$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 -> TimeUnit -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (TimeUnit -> Pair) -> Maybe TimeUnit -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TimeUnit
unit
]
)