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

-- | A policy enabling one or more entities to put logs to a log group in
-- this account.
--
-- /See:/ 'newResourcePolicy' smart constructor.
data ResourcePolicy = ResourcePolicy'
  { -- | 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,
    -- | The details of the policy.
    ResourcePolicy -> Maybe Text
policyDocument :: Prelude.Maybe Prelude.Text,
    -- | The name of the resource policy.
    ResourcePolicy -> Maybe Text
policyName :: Prelude.Maybe Prelude.Text
  }
  deriving (ResourcePolicy -> ResourcePolicy -> Bool
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]
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
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. 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:
--
-- '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@.
--
-- 'policyDocument', 'resourcePolicy_policyDocument' - The details of the policy.
--
-- 'policyName', 'resourcePolicy_policyName' - The name of the resource policy.
newResourcePolicy ::
  ResourcePolicy
newResourcePolicy :: ResourcePolicy
newResourcePolicy =
  ResourcePolicy'
    { $sel:lastUpdatedTime:ResourcePolicy' :: Maybe Natural
lastUpdatedTime = forall a. Maybe a
Prelude.Nothing,
      $sel:policyDocument:ResourcePolicy' :: Maybe Text
policyDocument = forall a. Maybe a
Prelude.Nothing,
      $sel:policyName:ResourcePolicy' :: Maybe Text
policyName = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' ResourcePolicy (Maybe Natural)
resourcePolicy_lastUpdatedTime = 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)

-- | The details of the policy.
resourcePolicy_policyDocument :: Lens.Lens' ResourcePolicy (Prelude.Maybe Prelude.Text)
resourcePolicy_policyDocument :: Lens' ResourcePolicy (Maybe Text)
resourcePolicy_policyDocument = 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)

-- | The name of the resource policy.
resourcePolicy_policyName :: Lens.Lens' ResourcePolicy (Prelude.Maybe Prelude.Text)
resourcePolicy_policyName :: Lens' ResourcePolicy (Maybe Text)
resourcePolicy_policyName = 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)

instance Data.FromJSON ResourcePolicy where
  parseJSON :: Value -> Parser ResourcePolicy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ResourcePolicy"
      ( \Object
x ->
          Maybe Natural -> Maybe Text -> Maybe Text -> ResourcePolicy
ResourcePolicy'
            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
"lastUpdatedTime")
            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
"policyDocument")
            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 ResourcePolicy where
  hashWithSalt :: Int -> ResourcePolicy -> Int
hashWithSalt Int
_salt ResourcePolicy' {Maybe Natural
Maybe Text
policyName :: Maybe Text
policyDocument :: Maybe Text
lastUpdatedTime :: Maybe Natural
$sel:policyName:ResourcePolicy' :: ResourcePolicy -> Maybe Text
$sel:policyDocument:ResourcePolicy' :: ResourcePolicy -> Maybe Text
$sel:lastUpdatedTime:ResourcePolicy' :: ResourcePolicy -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
lastUpdatedTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
policyDocument
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
policyName

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