{-# 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.LicenseManager.Types.DatetimeRange
-- 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.LicenseManager.Types.DatetimeRange where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes a time range, in ISO8601-UTC format.
--
-- /See:/ 'newDatetimeRange' smart constructor.
data DatetimeRange = DatetimeRange'
  { -- | End of the time range.
    DatetimeRange -> Maybe Text
end :: Prelude.Maybe Prelude.Text,
    -- | Start of the time range.
    DatetimeRange -> Text
begin :: Prelude.Text
  }
  deriving (DatetimeRange -> DatetimeRange -> Bool
(DatetimeRange -> DatetimeRange -> Bool)
-> (DatetimeRange -> DatetimeRange -> Bool) -> Eq DatetimeRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DatetimeRange -> DatetimeRange -> Bool
$c/= :: DatetimeRange -> DatetimeRange -> Bool
== :: DatetimeRange -> DatetimeRange -> Bool
$c== :: DatetimeRange -> DatetimeRange -> Bool
Prelude.Eq, ReadPrec [DatetimeRange]
ReadPrec DatetimeRange
Int -> ReadS DatetimeRange
ReadS [DatetimeRange]
(Int -> ReadS DatetimeRange)
-> ReadS [DatetimeRange]
-> ReadPrec DatetimeRange
-> ReadPrec [DatetimeRange]
-> Read DatetimeRange
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DatetimeRange]
$creadListPrec :: ReadPrec [DatetimeRange]
readPrec :: ReadPrec DatetimeRange
$creadPrec :: ReadPrec DatetimeRange
readList :: ReadS [DatetimeRange]
$creadList :: ReadS [DatetimeRange]
readsPrec :: Int -> ReadS DatetimeRange
$creadsPrec :: Int -> ReadS DatetimeRange
Prelude.Read, Int -> DatetimeRange -> ShowS
[DatetimeRange] -> ShowS
DatetimeRange -> String
(Int -> DatetimeRange -> ShowS)
-> (DatetimeRange -> String)
-> ([DatetimeRange] -> ShowS)
-> Show DatetimeRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DatetimeRange] -> ShowS
$cshowList :: [DatetimeRange] -> ShowS
show :: DatetimeRange -> String
$cshow :: DatetimeRange -> String
showsPrec :: Int -> DatetimeRange -> ShowS
$cshowsPrec :: Int -> DatetimeRange -> ShowS
Prelude.Show, (forall x. DatetimeRange -> Rep DatetimeRange x)
-> (forall x. Rep DatetimeRange x -> DatetimeRange)
-> Generic DatetimeRange
forall x. Rep DatetimeRange x -> DatetimeRange
forall x. DatetimeRange -> Rep DatetimeRange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DatetimeRange x -> DatetimeRange
$cfrom :: forall x. DatetimeRange -> Rep DatetimeRange x
Prelude.Generic)

-- |
-- Create a value of 'DatetimeRange' 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:
--
-- 'end', 'datetimeRange_end' - End of the time range.
--
-- 'begin', 'datetimeRange_begin' - Start of the time range.
newDatetimeRange ::
  -- | 'begin'
  Prelude.Text ->
  DatetimeRange
newDatetimeRange :: Text -> DatetimeRange
newDatetimeRange Text
pBegin_ =
  DatetimeRange' :: Maybe Text -> Text -> DatetimeRange
DatetimeRange'
    { $sel:end:DatetimeRange' :: Maybe Text
end = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:begin:DatetimeRange' :: Text
begin = Text
pBegin_
    }

-- | End of the time range.
datetimeRange_end :: Lens.Lens' DatetimeRange (Prelude.Maybe Prelude.Text)
datetimeRange_end :: (Maybe Text -> f (Maybe Text)) -> DatetimeRange -> f DatetimeRange
datetimeRange_end = (DatetimeRange -> Maybe Text)
-> (DatetimeRange -> Maybe Text -> DatetimeRange)
-> Lens DatetimeRange DatetimeRange (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatetimeRange' {Maybe Text
end :: Maybe Text
$sel:end:DatetimeRange' :: DatetimeRange -> Maybe Text
end} -> Maybe Text
end) (\s :: DatetimeRange
s@DatetimeRange' {} Maybe Text
a -> DatetimeRange
s {$sel:end:DatetimeRange' :: Maybe Text
end = Maybe Text
a} :: DatetimeRange)

-- | Start of the time range.
datetimeRange_begin :: Lens.Lens' DatetimeRange Prelude.Text
datetimeRange_begin :: (Text -> f Text) -> DatetimeRange -> f DatetimeRange
datetimeRange_begin = (DatetimeRange -> Text)
-> (DatetimeRange -> Text -> DatetimeRange)
-> Lens DatetimeRange DatetimeRange Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatetimeRange' {Text
begin :: Text
$sel:begin:DatetimeRange' :: DatetimeRange -> Text
begin} -> Text
begin) (\s :: DatetimeRange
s@DatetimeRange' {} Text
a -> DatetimeRange
s {$sel:begin:DatetimeRange' :: Text
begin = Text
a} :: DatetimeRange)

instance Core.FromJSON DatetimeRange where
  parseJSON :: Value -> Parser DatetimeRange
parseJSON =
    String
-> (Object -> Parser DatetimeRange)
-> Value
-> Parser DatetimeRange
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DatetimeRange"
      ( \Object
x ->
          Maybe Text -> Text -> DatetimeRange
DatetimeRange'
            (Maybe Text -> Text -> DatetimeRange)
-> Parser (Maybe Text) -> Parser (Text -> DatetimeRange)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"End") Parser (Text -> DatetimeRange)
-> Parser Text -> Parser DatetimeRange
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Begin")
      )

instance Prelude.Hashable DatetimeRange

instance Prelude.NFData DatetimeRange

instance Core.ToJSON DatetimeRange where
  toJSON :: DatetimeRange -> Value
toJSON DatetimeRange' {Maybe Text
Text
begin :: Text
end :: Maybe Text
$sel:begin:DatetimeRange' :: DatetimeRange -> Text
$sel:end:DatetimeRange' :: DatetimeRange -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"End" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
end,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Begin" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
begin)
          ]
      )