{-# 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.Signer.Types.SignatureValidityPeriod
-- 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.Signer.Types.SignatureValidityPeriod where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Signer.Types.ValidityType

-- | The validity period for a signing job.
--
-- /See:/ 'newSignatureValidityPeriod' smart constructor.
data SignatureValidityPeriod = SignatureValidityPeriod'
  { -- | The numerical value of the time unit for signature validity.
    SignatureValidityPeriod -> Maybe Int
value :: Prelude.Maybe Prelude.Int,
    -- | The time unit for signature validity.
    SignatureValidityPeriod -> Maybe ValidityType
type' :: Prelude.Maybe ValidityType
  }
  deriving (SignatureValidityPeriod -> SignatureValidityPeriod -> Bool
(SignatureValidityPeriod -> SignatureValidityPeriod -> Bool)
-> (SignatureValidityPeriod -> SignatureValidityPeriod -> Bool)
-> Eq SignatureValidityPeriod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SignatureValidityPeriod -> SignatureValidityPeriod -> Bool
$c/= :: SignatureValidityPeriod -> SignatureValidityPeriod -> Bool
== :: SignatureValidityPeriod -> SignatureValidityPeriod -> Bool
$c== :: SignatureValidityPeriod -> SignatureValidityPeriod -> Bool
Prelude.Eq, ReadPrec [SignatureValidityPeriod]
ReadPrec SignatureValidityPeriod
Int -> ReadS SignatureValidityPeriod
ReadS [SignatureValidityPeriod]
(Int -> ReadS SignatureValidityPeriod)
-> ReadS [SignatureValidityPeriod]
-> ReadPrec SignatureValidityPeriod
-> ReadPrec [SignatureValidityPeriod]
-> Read SignatureValidityPeriod
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SignatureValidityPeriod]
$creadListPrec :: ReadPrec [SignatureValidityPeriod]
readPrec :: ReadPrec SignatureValidityPeriod
$creadPrec :: ReadPrec SignatureValidityPeriod
readList :: ReadS [SignatureValidityPeriod]
$creadList :: ReadS [SignatureValidityPeriod]
readsPrec :: Int -> ReadS SignatureValidityPeriod
$creadsPrec :: Int -> ReadS SignatureValidityPeriod
Prelude.Read, Int -> SignatureValidityPeriod -> ShowS
[SignatureValidityPeriod] -> ShowS
SignatureValidityPeriod -> String
(Int -> SignatureValidityPeriod -> ShowS)
-> (SignatureValidityPeriod -> String)
-> ([SignatureValidityPeriod] -> ShowS)
-> Show SignatureValidityPeriod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SignatureValidityPeriod] -> ShowS
$cshowList :: [SignatureValidityPeriod] -> ShowS
show :: SignatureValidityPeriod -> String
$cshow :: SignatureValidityPeriod -> String
showsPrec :: Int -> SignatureValidityPeriod -> ShowS
$cshowsPrec :: Int -> SignatureValidityPeriod -> ShowS
Prelude.Show, (forall x.
 SignatureValidityPeriod -> Rep SignatureValidityPeriod x)
-> (forall x.
    Rep SignatureValidityPeriod x -> SignatureValidityPeriod)
-> Generic SignatureValidityPeriod
forall x. Rep SignatureValidityPeriod x -> SignatureValidityPeriod
forall x. SignatureValidityPeriod -> Rep SignatureValidityPeriod x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SignatureValidityPeriod x -> SignatureValidityPeriod
$cfrom :: forall x. SignatureValidityPeriod -> Rep SignatureValidityPeriod x
Prelude.Generic)

-- |
-- Create a value of 'SignatureValidityPeriod' 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', 'signatureValidityPeriod_value' - The numerical value of the time unit for signature validity.
--
-- 'type'', 'signatureValidityPeriod_type' - The time unit for signature validity.
newSignatureValidityPeriod ::
  SignatureValidityPeriod
newSignatureValidityPeriod :: SignatureValidityPeriod
newSignatureValidityPeriod =
  SignatureValidityPeriod' :: Maybe Int -> Maybe ValidityType -> SignatureValidityPeriod
SignatureValidityPeriod'
    { $sel:value:SignatureValidityPeriod' :: Maybe Int
value = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:type':SignatureValidityPeriod' :: Maybe ValidityType
type' = Maybe ValidityType
forall a. Maybe a
Prelude.Nothing
    }

-- | The numerical value of the time unit for signature validity.
signatureValidityPeriod_value :: Lens.Lens' SignatureValidityPeriod (Prelude.Maybe Prelude.Int)
signatureValidityPeriod_value :: (Maybe Int -> f (Maybe Int))
-> SignatureValidityPeriod -> f SignatureValidityPeriod
signatureValidityPeriod_value = (SignatureValidityPeriod -> Maybe Int)
-> (SignatureValidityPeriod
    -> Maybe Int -> SignatureValidityPeriod)
-> Lens
     SignatureValidityPeriod
     SignatureValidityPeriod
     (Maybe Int)
     (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SignatureValidityPeriod' {Maybe Int
value :: Maybe Int
$sel:value:SignatureValidityPeriod' :: SignatureValidityPeriod -> Maybe Int
value} -> Maybe Int
value) (\s :: SignatureValidityPeriod
s@SignatureValidityPeriod' {} Maybe Int
a -> SignatureValidityPeriod
s {$sel:value:SignatureValidityPeriod' :: Maybe Int
value = Maybe Int
a} :: SignatureValidityPeriod)

-- | The time unit for signature validity.
signatureValidityPeriod_type :: Lens.Lens' SignatureValidityPeriod (Prelude.Maybe ValidityType)
signatureValidityPeriod_type :: (Maybe ValidityType -> f (Maybe ValidityType))
-> SignatureValidityPeriod -> f SignatureValidityPeriod
signatureValidityPeriod_type = (SignatureValidityPeriod -> Maybe ValidityType)
-> (SignatureValidityPeriod
    -> Maybe ValidityType -> SignatureValidityPeriod)
-> Lens
     SignatureValidityPeriod
     SignatureValidityPeriod
     (Maybe ValidityType)
     (Maybe ValidityType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SignatureValidityPeriod' {Maybe ValidityType
type' :: Maybe ValidityType
$sel:type':SignatureValidityPeriod' :: SignatureValidityPeriod -> Maybe ValidityType
type'} -> Maybe ValidityType
type') (\s :: SignatureValidityPeriod
s@SignatureValidityPeriod' {} Maybe ValidityType
a -> SignatureValidityPeriod
s {$sel:type':SignatureValidityPeriod' :: Maybe ValidityType
type' = Maybe ValidityType
a} :: SignatureValidityPeriod)

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

instance Prelude.Hashable SignatureValidityPeriod

instance Prelude.NFData SignatureValidityPeriod

instance Core.ToJSON SignatureValidityPeriod where
  toJSON :: SignatureValidityPeriod -> Value
toJSON SignatureValidityPeriod' {Maybe Int
Maybe ValidityType
type' :: Maybe ValidityType
value :: Maybe Int
$sel:type':SignatureValidityPeriod' :: SignatureValidityPeriod -> Maybe ValidityType
$sel:value:SignatureValidityPeriod' :: SignatureValidityPeriod -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"value" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
value,
            (Text
"type" Text -> ValidityType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ValidityType -> Pair) -> Maybe ValidityType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ValidityType
type'
          ]
      )