{-# 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.CloudWatchLogs.Types.ResourcePolicy
-- 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.CloudWatchLogs.Types.ResourcePolicy where

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

-- | A policy enabling one or more entities to put logs to a log group in
-- this account.
--
-- /See:/ 'newResourcePolicy' smart constructor.
data ResourcePolicy = ResourcePolicy'
  { -- | The name of the resource policy.
    ResourcePolicy -> Maybe Text
policyName :: Prelude.Maybe Prelude.Text,
    -- | The details of the policy.
    ResourcePolicy -> Maybe Text
policyDocument :: Prelude.Maybe Prelude.Text,
    -- | Timestamp showing when this policy was last updated, expressed as the
    -- number of milliseconds after Jan 1, 1970 00:00:00 UTC.
    ResourcePolicy -> Maybe Natural
lastUpdatedTime :: Prelude.Maybe Prelude.Natural
  }
  deriving (ResourcePolicy -> ResourcePolicy -> Bool
(ResourcePolicy -> ResourcePolicy -> Bool)
-> (ResourcePolicy -> ResourcePolicy -> Bool) -> Eq ResourcePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourcePolicy -> ResourcePolicy -> Bool
$c/= :: ResourcePolicy -> ResourcePolicy -> Bool
== :: ResourcePolicy -> ResourcePolicy -> Bool
$c== :: ResourcePolicy -> ResourcePolicy -> Bool
Prelude.Eq, ReadPrec [ResourcePolicy]
ReadPrec ResourcePolicy
Int -> ReadS ResourcePolicy
ReadS [ResourcePolicy]
(Int -> ReadS ResourcePolicy)
-> ReadS [ResourcePolicy]
-> ReadPrec ResourcePolicy
-> ReadPrec [ResourcePolicy]
-> Read ResourcePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourcePolicy]
$creadListPrec :: ReadPrec [ResourcePolicy]
readPrec :: ReadPrec ResourcePolicy
$creadPrec :: ReadPrec ResourcePolicy
readList :: ReadS [ResourcePolicy]
$creadList :: ReadS [ResourcePolicy]
readsPrec :: Int -> ReadS ResourcePolicy
$creadsPrec :: Int -> ReadS ResourcePolicy
Prelude.Read, Int -> ResourcePolicy -> ShowS
[ResourcePolicy] -> ShowS
ResourcePolicy -> String
(Int -> ResourcePolicy -> ShowS)
-> (ResourcePolicy -> String)
-> ([ResourcePolicy] -> ShowS)
-> Show ResourcePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourcePolicy] -> ShowS
$cshowList :: [ResourcePolicy] -> ShowS
show :: ResourcePolicy -> String
$cshow :: ResourcePolicy -> String
showsPrec :: Int -> ResourcePolicy -> ShowS
$cshowsPrec :: Int -> ResourcePolicy -> ShowS
Prelude.Show, (forall x. ResourcePolicy -> Rep ResourcePolicy x)
-> (forall x. Rep ResourcePolicy x -> ResourcePolicy)
-> Generic ResourcePolicy
forall x. Rep ResourcePolicy x -> ResourcePolicy
forall x. ResourcePolicy -> Rep ResourcePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourcePolicy x -> ResourcePolicy
$cfrom :: forall x. ResourcePolicy -> Rep ResourcePolicy x
Prelude.Generic)

-- |
-- Create a value of 'ResourcePolicy' 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', 'resourcePolicy_policyName' - The name of the resource policy.
--
-- 'policyDocument', 'resourcePolicy_policyDocument' - The details of the policy.
--
-- 'lastUpdatedTime', 'resourcePolicy_lastUpdatedTime' - Timestamp showing when this policy was last updated, expressed as the
-- number of milliseconds after Jan 1, 1970 00:00:00 UTC.
newResourcePolicy ::
  ResourcePolicy
newResourcePolicy :: ResourcePolicy
newResourcePolicy =
  ResourcePolicy' :: Maybe Text -> Maybe Text -> Maybe Natural -> ResourcePolicy
ResourcePolicy'
    { $sel:policyName:ResourcePolicy' :: Maybe Text
policyName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policyDocument:ResourcePolicy' :: Maybe Text
policyDocument = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:lastUpdatedTime:ResourcePolicy' :: Maybe Natural
lastUpdatedTime = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the resource policy.
resourcePolicy_policyName :: Lens.Lens' ResourcePolicy (Prelude.Maybe Prelude.Text)
resourcePolicy_policyName :: (Maybe Text -> f (Maybe Text))
-> ResourcePolicy -> f ResourcePolicy
resourcePolicy_policyName = (ResourcePolicy -> Maybe Text)
-> (ResourcePolicy -> Maybe Text -> ResourcePolicy)
-> Lens ResourcePolicy ResourcePolicy (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePolicy' {Maybe Text
policyName :: Maybe Text
$sel:policyName:ResourcePolicy' :: ResourcePolicy -> Maybe Text
policyName} -> Maybe Text
policyName) (\s :: ResourcePolicy
s@ResourcePolicy' {} Maybe Text
a -> ResourcePolicy
s {$sel:policyName:ResourcePolicy' :: Maybe Text
policyName = Maybe Text
a} :: ResourcePolicy)

-- | The details of the policy.
resourcePolicy_policyDocument :: Lens.Lens' ResourcePolicy (Prelude.Maybe Prelude.Text)
resourcePolicy_policyDocument :: (Maybe Text -> f (Maybe Text))
-> ResourcePolicy -> f ResourcePolicy
resourcePolicy_policyDocument = (ResourcePolicy -> Maybe Text)
-> (ResourcePolicy -> Maybe Text -> ResourcePolicy)
-> Lens ResourcePolicy ResourcePolicy (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePolicy' {Maybe Text
policyDocument :: Maybe Text
$sel:policyDocument:ResourcePolicy' :: ResourcePolicy -> Maybe Text
policyDocument} -> Maybe Text
policyDocument) (\s :: ResourcePolicy
s@ResourcePolicy' {} Maybe Text
a -> ResourcePolicy
s {$sel:policyDocument:ResourcePolicy' :: Maybe Text
policyDocument = Maybe Text
a} :: ResourcePolicy)

-- | Timestamp showing when this policy was last updated, expressed as the
-- number of milliseconds after Jan 1, 1970 00:00:00 UTC.
resourcePolicy_lastUpdatedTime :: Lens.Lens' ResourcePolicy (Prelude.Maybe Prelude.Natural)
resourcePolicy_lastUpdatedTime :: (Maybe Natural -> f (Maybe Natural))
-> ResourcePolicy -> f ResourcePolicy
resourcePolicy_lastUpdatedTime = (ResourcePolicy -> Maybe Natural)
-> (ResourcePolicy -> Maybe Natural -> ResourcePolicy)
-> Lens
     ResourcePolicy ResourcePolicy (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePolicy' {Maybe Natural
lastUpdatedTime :: Maybe Natural
$sel:lastUpdatedTime:ResourcePolicy' :: ResourcePolicy -> Maybe Natural
lastUpdatedTime} -> Maybe Natural
lastUpdatedTime) (\s :: ResourcePolicy
s@ResourcePolicy' {} Maybe Natural
a -> ResourcePolicy
s {$sel:lastUpdatedTime:ResourcePolicy' :: Maybe Natural
lastUpdatedTime = Maybe Natural
a} :: ResourcePolicy)

instance Core.FromJSON ResourcePolicy where
  parseJSON :: Value -> Parser ResourcePolicy
parseJSON =
    String
-> (Object -> Parser ResourcePolicy)
-> Value
-> Parser ResourcePolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResourcePolicy"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Maybe Natural -> ResourcePolicy
ResourcePolicy'
            (Maybe Text -> Maybe Text -> Maybe Natural -> ResourcePolicy)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Natural -> ResourcePolicy)
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 -> Maybe Natural -> ResourcePolicy)
-> Parser (Maybe Text) -> Parser (Maybe Natural -> ResourcePolicy)
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
"policyDocument")
            Parser (Maybe Natural -> ResourcePolicy)
-> Parser (Maybe Natural) -> Parser ResourcePolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"lastUpdatedTime")
      )

instance Prelude.Hashable ResourcePolicy

instance Prelude.NFData ResourcePolicy