{-# 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.Policy
-- 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.Policy 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 an IoT policy.
--
-- /See:/ 'newPolicy' smart constructor.
data Policy = Policy'
  { -- | The policy ARN.
    Policy -> Maybe Text
policyArn :: Prelude.Maybe Prelude.Text,
    -- | The policy name.
    Policy -> Maybe Text
policyName :: Prelude.Maybe Prelude.Text
  }
  deriving (Policy -> Policy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Policy -> Policy -> Bool
$c/= :: Policy -> Policy -> Bool
== :: Policy -> Policy -> Bool
$c== :: Policy -> Policy -> Bool
Prelude.Eq, ReadPrec [Policy]
ReadPrec Policy
Int -> ReadS Policy
ReadS [Policy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Policy]
$creadListPrec :: ReadPrec [Policy]
readPrec :: ReadPrec Policy
$creadPrec :: ReadPrec Policy
readList :: ReadS [Policy]
$creadList :: ReadS [Policy]
readsPrec :: Int -> ReadS Policy
$creadsPrec :: Int -> ReadS Policy
Prelude.Read, Int -> Policy -> ShowS
[Policy] -> ShowS
Policy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Policy] -> ShowS
$cshowList :: [Policy] -> ShowS
show :: Policy -> String
$cshow :: Policy -> String
showsPrec :: Int -> Policy -> ShowS
$cshowsPrec :: Int -> Policy -> ShowS
Prelude.Show, forall x. Rep Policy x -> Policy
forall x. Policy -> Rep Policy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Policy x -> Policy
$cfrom :: forall x. Policy -> Rep Policy x
Prelude.Generic)

-- |
-- Create a value of 'Policy' 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:
--
-- 'policyArn', 'policy_policyArn' - The policy ARN.
--
-- 'policyName', 'policy_policyName' - The policy name.
newPolicy ::
  Policy
newPolicy :: Policy
newPolicy =
  Policy'
    { $sel:policyArn:Policy' :: Maybe Text
policyArn = forall a. Maybe a
Prelude.Nothing,
      $sel:policyName:Policy' :: Maybe Text
policyName = forall a. Maybe a
Prelude.Nothing
    }

-- | The policy ARN.
policy_policyArn :: Lens.Lens' Policy (Prelude.Maybe Prelude.Text)
policy_policyArn :: Lens' Policy (Maybe Text)
policy_policyArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Policy' {Maybe Text
policyArn :: Maybe Text
$sel:policyArn:Policy' :: Policy -> Maybe Text
policyArn} -> Maybe Text
policyArn) (\s :: Policy
s@Policy' {} Maybe Text
a -> Policy
s {$sel:policyArn:Policy' :: Maybe Text
policyArn = Maybe Text
a} :: Policy)

-- | The policy name.
policy_policyName :: Lens.Lens' Policy (Prelude.Maybe Prelude.Text)
policy_policyName :: Lens' Policy (Maybe Text)
policy_policyName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Policy' {Maybe Text
policyName :: Maybe Text
$sel:policyName:Policy' :: Policy -> Maybe Text
policyName} -> Maybe Text
policyName) (\s :: Policy
s@Policy' {} Maybe Text
a -> Policy
s {$sel:policyName:Policy' :: Maybe Text
policyName = Maybe Text
a} :: Policy)

instance Data.FromJSON Policy where
  parseJSON :: Value -> Parser Policy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Policy"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Policy
Policy'
            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
"policyArn")
            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
"policyName")
      )

instance Prelude.Hashable Policy where
  hashWithSalt :: Int -> Policy -> Int
hashWithSalt Int
_salt Policy' {Maybe Text
policyName :: Maybe Text
policyArn :: Maybe Text
$sel:policyName:Policy' :: Policy -> Maybe Text
$sel:policyArn:Policy' :: Policy -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
policyArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
policyName

instance Prelude.NFData Policy where
  rnf :: Policy -> ()
rnf Policy' {Maybe Text
policyName :: Maybe Text
policyArn :: Maybe Text
$sel:policyName:Policy' :: Policy -> Maybe Text
$sel:policyArn:Policy' :: Policy -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
policyArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
policyName