{-# 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-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.IoT.Types.Policy where

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

-- | Describes an IoT policy.
--
-- /See:/ 'newPolicy' smart constructor.
data Policy = Policy'
  { -- | The policy name.
    Policy -> Maybe Text
policyName :: Prelude.Maybe Prelude.Text,
    -- | The policy ARN.
    Policy -> Maybe Text
policyArn :: Prelude.Maybe Prelude.Text
  }
  deriving (Policy -> Policy -> Bool
(Policy -> Policy -> Bool)
-> (Policy -> Policy -> Bool) -> Eq Policy
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]
(Int -> ReadS Policy)
-> ReadS [Policy]
-> ReadPrec Policy
-> ReadPrec [Policy]
-> Read 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
(Int -> Policy -> ShowS)
-> (Policy -> String) -> ([Policy] -> ShowS) -> Show Policy
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. Policy -> Rep Policy x)
-> (forall x. Rep Policy x -> Policy) -> Generic Policy
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:
--
-- 'policyName', 'policy_policyName' - The policy name.
--
-- 'policyArn', 'policy_policyArn' - The policy ARN.
newPolicy ::
  Policy
newPolicy :: Policy
newPolicy =
  Policy' :: Maybe Text -> Maybe Text -> Policy
Policy'
    { $sel:policyName:Policy' :: Maybe Text
policyName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policyArn:Policy' :: Maybe Text
policyArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The policy name.
policy_policyName :: Lens.Lens' Policy (Prelude.Maybe Prelude.Text)
policy_policyName :: (Maybe Text -> f (Maybe Text)) -> Policy -> f Policy
policy_policyName = (Policy -> Maybe Text)
-> (Policy -> Maybe Text -> Policy)
-> Lens Policy Policy (Maybe Text) (Maybe Text)
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)

-- | The policy ARN.
policy_policyArn :: Lens.Lens' Policy (Prelude.Maybe Prelude.Text)
policy_policyArn :: (Maybe Text -> f (Maybe Text)) -> Policy -> f Policy
policy_policyArn = (Policy -> Maybe Text)
-> (Policy -> Maybe Text -> Policy)
-> Lens Policy Policy (Maybe Text) (Maybe Text)
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)

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

instance Prelude.Hashable Policy

instance Prelude.NFData Policy