{-# 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 #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.ElasticSearch.Types.Duration
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ElasticSearch.Types.Duration where

import qualified Amazonka.Core as Core
import Amazonka.ElasticSearch.Types.TimeUnit
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies maintenance schedule duration: duration value and duration
-- unit. See the
-- <https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/auto-tune.html Developer Guide>
-- for more information.
--
-- /See:/ 'newDuration' smart constructor.
data Duration = Duration'
  { -- | Integer to specify the value of a maintenance schedule duration. See the
    -- <https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/auto-tune.html Developer Guide>
    -- for more information.
    Duration -> Maybe Natural
value :: Prelude.Maybe Prelude.Natural,
    -- | Specifies the unit of a maintenance schedule duration. Valid value is
    -- HOURS. See the
    -- <https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/auto-tune.html Developer Guide>
    -- for more information.
    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)

-- |
-- Create a value of 'Duration' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'value', 'duration_value' - Integer to specify the value of a maintenance schedule duration. See the
-- <https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/auto-tune.html Developer Guide>
-- for more information.
--
-- 'unit', 'duration_unit' - Specifies the unit of a maintenance schedule duration. Valid value is
-- HOURS. See the
-- <https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/auto-tune.html Developer Guide>
-- for more information.
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
    }

-- | Integer to specify the value of a maintenance schedule duration. See the
-- <https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/auto-tune.html Developer Guide>
-- for more information.
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)

-- | Specifies the unit of a maintenance schedule duration. Valid value is
-- HOURS. See the
-- <https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/auto-tune.html Developer Guide>
-- for more information.
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
          ]
      )