{-# 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.IoT.Types.PolicyVersion
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoT.Types.PolicyVersion where

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

-- | Describes a policy version.
--
-- /See:/ 'newPolicyVersion' smart constructor.
data PolicyVersion = PolicyVersion'
  { -- | The date and time the policy was created.
    PolicyVersion -> Maybe POSIX
createDate :: Prelude.Maybe Data.POSIX,
    -- | Specifies whether the policy version is the default.
    PolicyVersion -> Maybe Bool
isDefaultVersion :: Prelude.Maybe Prelude.Bool,
    -- | The policy version ID.
    PolicyVersion -> Maybe Text
versionId :: Prelude.Maybe Prelude.Text
  }
  deriving (PolicyVersion -> PolicyVersion -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PolicyVersion -> PolicyVersion -> Bool
$c/= :: PolicyVersion -> PolicyVersion -> Bool
== :: PolicyVersion -> PolicyVersion -> Bool
$c== :: PolicyVersion -> PolicyVersion -> Bool
Prelude.Eq, ReadPrec [PolicyVersion]
ReadPrec PolicyVersion
Int -> ReadS PolicyVersion
ReadS [PolicyVersion]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PolicyVersion]
$creadListPrec :: ReadPrec [PolicyVersion]
readPrec :: ReadPrec PolicyVersion
$creadPrec :: ReadPrec PolicyVersion
readList :: ReadS [PolicyVersion]
$creadList :: ReadS [PolicyVersion]
readsPrec :: Int -> ReadS PolicyVersion
$creadsPrec :: Int -> ReadS PolicyVersion
Prelude.Read, Int -> PolicyVersion -> ShowS
[PolicyVersion] -> ShowS
PolicyVersion -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PolicyVersion] -> ShowS
$cshowList :: [PolicyVersion] -> ShowS
show :: PolicyVersion -> String
$cshow :: PolicyVersion -> String
showsPrec :: Int -> PolicyVersion -> ShowS
$cshowsPrec :: Int -> PolicyVersion -> ShowS
Prelude.Show, forall x. Rep PolicyVersion x -> PolicyVersion
forall x. PolicyVersion -> Rep PolicyVersion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PolicyVersion x -> PolicyVersion
$cfrom :: forall x. PolicyVersion -> Rep PolicyVersion x
Prelude.Generic)

-- |
-- Create a value of 'PolicyVersion' 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:
--
-- 'createDate', 'policyVersion_createDate' - The date and time the policy was created.
--
-- 'isDefaultVersion', 'policyVersion_isDefaultVersion' - Specifies whether the policy version is the default.
--
-- 'versionId', 'policyVersion_versionId' - The policy version ID.
newPolicyVersion ::
  PolicyVersion
newPolicyVersion :: PolicyVersion
newPolicyVersion =
  PolicyVersion'
    { $sel:createDate:PolicyVersion' :: Maybe POSIX
createDate = forall a. Maybe a
Prelude.Nothing,
      $sel:isDefaultVersion:PolicyVersion' :: Maybe Bool
isDefaultVersion = forall a. Maybe a
Prelude.Nothing,
      $sel:versionId:PolicyVersion' :: Maybe Text
versionId = forall a. Maybe a
Prelude.Nothing
    }

-- | The date and time the policy was created.
policyVersion_createDate :: Lens.Lens' PolicyVersion (Prelude.Maybe Prelude.UTCTime)
policyVersion_createDate :: Lens' PolicyVersion (Maybe UTCTime)
policyVersion_createDate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyVersion' {Maybe POSIX
createDate :: Maybe POSIX
$sel:createDate:PolicyVersion' :: PolicyVersion -> Maybe POSIX
createDate} -> Maybe POSIX
createDate) (\s :: PolicyVersion
s@PolicyVersion' {} Maybe POSIX
a -> PolicyVersion
s {$sel:createDate:PolicyVersion' :: Maybe POSIX
createDate = Maybe POSIX
a} :: PolicyVersion) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | Specifies whether the policy version is the default.
policyVersion_isDefaultVersion :: Lens.Lens' PolicyVersion (Prelude.Maybe Prelude.Bool)
policyVersion_isDefaultVersion :: Lens' PolicyVersion (Maybe Bool)
policyVersion_isDefaultVersion = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyVersion' {Maybe Bool
isDefaultVersion :: Maybe Bool
$sel:isDefaultVersion:PolicyVersion' :: PolicyVersion -> Maybe Bool
isDefaultVersion} -> Maybe Bool
isDefaultVersion) (\s :: PolicyVersion
s@PolicyVersion' {} Maybe Bool
a -> PolicyVersion
s {$sel:isDefaultVersion:PolicyVersion' :: Maybe Bool
isDefaultVersion = Maybe Bool
a} :: PolicyVersion)

-- | The policy version ID.
policyVersion_versionId :: Lens.Lens' PolicyVersion (Prelude.Maybe Prelude.Text)
policyVersion_versionId :: Lens' PolicyVersion (Maybe Text)
policyVersion_versionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PolicyVersion' {Maybe Text
versionId :: Maybe Text
$sel:versionId:PolicyVersion' :: PolicyVersion -> Maybe Text
versionId} -> Maybe Text
versionId) (\s :: PolicyVersion
s@PolicyVersion' {} Maybe Text
a -> PolicyVersion
s {$sel:versionId:PolicyVersion' :: Maybe Text
versionId = Maybe Text
a} :: PolicyVersion)

instance Data.FromJSON PolicyVersion where
  parseJSON :: Value -> Parser PolicyVersion
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PolicyVersion"
      ( \Object
x ->
          Maybe POSIX -> Maybe Bool -> Maybe Text -> PolicyVersion
PolicyVersion'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"createDate")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"isDefaultVersion")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"versionId")
      )

instance Prelude.Hashable PolicyVersion where
  hashWithSalt :: Int -> PolicyVersion -> Int
hashWithSalt Int
_salt PolicyVersion' {Maybe Bool
Maybe Text
Maybe POSIX
versionId :: Maybe Text
isDefaultVersion :: Maybe Bool
createDate :: Maybe POSIX
$sel:versionId:PolicyVersion' :: PolicyVersion -> Maybe Text
$sel:isDefaultVersion:PolicyVersion' :: PolicyVersion -> Maybe Bool
$sel:createDate:PolicyVersion' :: PolicyVersion -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
createDate
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
isDefaultVersion
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
versionId

instance Prelude.NFData PolicyVersion where
  rnf :: PolicyVersion -> ()
rnf PolicyVersion' {Maybe Bool
Maybe Text
Maybe POSIX
versionId :: Maybe Text
isDefaultVersion :: Maybe Bool
createDate :: Maybe POSIX
$sel:versionId:PolicyVersion' :: PolicyVersion -> Maybe Text
$sel:isDefaultVersion:PolicyVersion' :: PolicyVersion -> Maybe Bool
$sel:createDate:PolicyVersion' :: PolicyVersion -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
createDate
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
isDefaultVersion
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
versionId