{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.PutRetentionPolicy
-- 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)
--
-- Sets the retention of the specified log group. A retention policy allows
-- you to configure the number of days for which to retain log events in
-- the specified log group.
module Amazonka.CloudWatchLogs.PutRetentionPolicy
  ( -- * Creating a Request
    PutRetentionPolicy (..),
    newPutRetentionPolicy,

    -- * Request Lenses
    putRetentionPolicy_logGroupName,
    putRetentionPolicy_retentionInDays,

    -- * Destructuring the Response
    PutRetentionPolicyResponse (..),
    newPutRetentionPolicyResponse,
  )
where

import Amazonka.CloudWatchLogs.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newPutRetentionPolicy' smart constructor.
data PutRetentionPolicy = PutRetentionPolicy'
  { -- | The name of the log group.
    PutRetentionPolicy -> Text
logGroupName :: Prelude.Text,
    PutRetentionPolicy -> Int
retentionInDays :: Prelude.Int
  }
  deriving (PutRetentionPolicy -> PutRetentionPolicy -> Bool
(PutRetentionPolicy -> PutRetentionPolicy -> Bool)
-> (PutRetentionPolicy -> PutRetentionPolicy -> Bool)
-> Eq PutRetentionPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRetentionPolicy -> PutRetentionPolicy -> Bool
$c/= :: PutRetentionPolicy -> PutRetentionPolicy -> Bool
== :: PutRetentionPolicy -> PutRetentionPolicy -> Bool
$c== :: PutRetentionPolicy -> PutRetentionPolicy -> Bool
Prelude.Eq, ReadPrec [PutRetentionPolicy]
ReadPrec PutRetentionPolicy
Int -> ReadS PutRetentionPolicy
ReadS [PutRetentionPolicy]
(Int -> ReadS PutRetentionPolicy)
-> ReadS [PutRetentionPolicy]
-> ReadPrec PutRetentionPolicy
-> ReadPrec [PutRetentionPolicy]
-> Read PutRetentionPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRetentionPolicy]
$creadListPrec :: ReadPrec [PutRetentionPolicy]
readPrec :: ReadPrec PutRetentionPolicy
$creadPrec :: ReadPrec PutRetentionPolicy
readList :: ReadS [PutRetentionPolicy]
$creadList :: ReadS [PutRetentionPolicy]
readsPrec :: Int -> ReadS PutRetentionPolicy
$creadsPrec :: Int -> ReadS PutRetentionPolicy
Prelude.Read, Int -> PutRetentionPolicy -> ShowS
[PutRetentionPolicy] -> ShowS
PutRetentionPolicy -> String
(Int -> PutRetentionPolicy -> ShowS)
-> (PutRetentionPolicy -> String)
-> ([PutRetentionPolicy] -> ShowS)
-> Show PutRetentionPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRetentionPolicy] -> ShowS
$cshowList :: [PutRetentionPolicy] -> ShowS
show :: PutRetentionPolicy -> String
$cshow :: PutRetentionPolicy -> String
showsPrec :: Int -> PutRetentionPolicy -> ShowS
$cshowsPrec :: Int -> PutRetentionPolicy -> ShowS
Prelude.Show, (forall x. PutRetentionPolicy -> Rep PutRetentionPolicy x)
-> (forall x. Rep PutRetentionPolicy x -> PutRetentionPolicy)
-> Generic PutRetentionPolicy
forall x. Rep PutRetentionPolicy x -> PutRetentionPolicy
forall x. PutRetentionPolicy -> Rep PutRetentionPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutRetentionPolicy x -> PutRetentionPolicy
$cfrom :: forall x. PutRetentionPolicy -> Rep PutRetentionPolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutRetentionPolicy' 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:
--
-- 'logGroupName', 'putRetentionPolicy_logGroupName' - The name of the log group.
--
-- 'retentionInDays', 'putRetentionPolicy_retentionInDays' - Undocumented member.
newPutRetentionPolicy ::
  -- | 'logGroupName'
  Prelude.Text ->
  -- | 'retentionInDays'
  Prelude.Int ->
  PutRetentionPolicy
newPutRetentionPolicy :: Text -> Int -> PutRetentionPolicy
newPutRetentionPolicy
  Text
pLogGroupName_
  Int
pRetentionInDays_ =
    PutRetentionPolicy' :: Text -> Int -> PutRetentionPolicy
PutRetentionPolicy'
      { $sel:logGroupName:PutRetentionPolicy' :: Text
logGroupName = Text
pLogGroupName_,
        $sel:retentionInDays:PutRetentionPolicy' :: Int
retentionInDays = Int
pRetentionInDays_
      }

-- | The name of the log group.
putRetentionPolicy_logGroupName :: Lens.Lens' PutRetentionPolicy Prelude.Text
putRetentionPolicy_logGroupName :: (Text -> f Text) -> PutRetentionPolicy -> f PutRetentionPolicy
putRetentionPolicy_logGroupName = (PutRetentionPolicy -> Text)
-> (PutRetentionPolicy -> Text -> PutRetentionPolicy)
-> Lens PutRetentionPolicy PutRetentionPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRetentionPolicy' {Text
logGroupName :: Text
$sel:logGroupName:PutRetentionPolicy' :: PutRetentionPolicy -> Text
logGroupName} -> Text
logGroupName) (\s :: PutRetentionPolicy
s@PutRetentionPolicy' {} Text
a -> PutRetentionPolicy
s {$sel:logGroupName:PutRetentionPolicy' :: Text
logGroupName = Text
a} :: PutRetentionPolicy)

-- | Undocumented member.
putRetentionPolicy_retentionInDays :: Lens.Lens' PutRetentionPolicy Prelude.Int
putRetentionPolicy_retentionInDays :: (Int -> f Int) -> PutRetentionPolicy -> f PutRetentionPolicy
putRetentionPolicy_retentionInDays = (PutRetentionPolicy -> Int)
-> (PutRetentionPolicy -> Int -> PutRetentionPolicy)
-> Lens PutRetentionPolicy PutRetentionPolicy Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRetentionPolicy' {Int
retentionInDays :: Int
$sel:retentionInDays:PutRetentionPolicy' :: PutRetentionPolicy -> Int
retentionInDays} -> Int
retentionInDays) (\s :: PutRetentionPolicy
s@PutRetentionPolicy' {} Int
a -> PutRetentionPolicy
s {$sel:retentionInDays:PutRetentionPolicy' :: Int
retentionInDays = Int
a} :: PutRetentionPolicy)

instance Core.AWSRequest PutRetentionPolicy where
  type
    AWSResponse PutRetentionPolicy =
      PutRetentionPolicyResponse
  request :: PutRetentionPolicy -> Request PutRetentionPolicy
request = Service -> PutRetentionPolicy -> Request PutRetentionPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutRetentionPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutRetentionPolicy)))
response =
    AWSResponse PutRetentionPolicy
-> Logger
-> Service
-> Proxy PutRetentionPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutRetentionPolicy)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse PutRetentionPolicy
PutRetentionPolicyResponse
PutRetentionPolicyResponse'

instance Prelude.Hashable PutRetentionPolicy

instance Prelude.NFData PutRetentionPolicy

instance Core.ToHeaders PutRetentionPolicy where
  toHeaders :: PutRetentionPolicy -> [Header]
toHeaders =
    [Header] -> PutRetentionPolicy -> [Header]
forall a b. a -> b -> a
Prelude.const
      ( [[Header]] -> [Header]
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# ( ByteString
"Logs_20140328.PutRetentionPolicy" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON PutRetentionPolicy where
  toJSON :: PutRetentionPolicy -> Value
toJSON PutRetentionPolicy' {Int
Text
retentionInDays :: Int
logGroupName :: Text
$sel:retentionInDays:PutRetentionPolicy' :: PutRetentionPolicy -> Int
$sel:logGroupName:PutRetentionPolicy' :: PutRetentionPolicy -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"logGroupName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
logGroupName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"retentionInDays" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
retentionInDays)
          ]
      )

instance Core.ToPath PutRetentionPolicy where
  toPath :: PutRetentionPolicy -> ByteString
toPath = ByteString -> PutRetentionPolicy -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery PutRetentionPolicy where
  toQuery :: PutRetentionPolicy -> QueryString
toQuery = QueryString -> PutRetentionPolicy -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newPutRetentionPolicyResponse' smart constructor.
data PutRetentionPolicyResponse = PutRetentionPolicyResponse'
  {
  }
  deriving (PutRetentionPolicyResponse -> PutRetentionPolicyResponse -> Bool
(PutRetentionPolicyResponse -> PutRetentionPolicyResponse -> Bool)
-> (PutRetentionPolicyResponse
    -> PutRetentionPolicyResponse -> Bool)
-> Eq PutRetentionPolicyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRetentionPolicyResponse -> PutRetentionPolicyResponse -> Bool
$c/= :: PutRetentionPolicyResponse -> PutRetentionPolicyResponse -> Bool
== :: PutRetentionPolicyResponse -> PutRetentionPolicyResponse -> Bool
$c== :: PutRetentionPolicyResponse -> PutRetentionPolicyResponse -> Bool
Prelude.Eq, ReadPrec [PutRetentionPolicyResponse]
ReadPrec PutRetentionPolicyResponse
Int -> ReadS PutRetentionPolicyResponse
ReadS [PutRetentionPolicyResponse]
(Int -> ReadS PutRetentionPolicyResponse)
-> ReadS [PutRetentionPolicyResponse]
-> ReadPrec PutRetentionPolicyResponse
-> ReadPrec [PutRetentionPolicyResponse]
-> Read PutRetentionPolicyResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRetentionPolicyResponse]
$creadListPrec :: ReadPrec [PutRetentionPolicyResponse]
readPrec :: ReadPrec PutRetentionPolicyResponse
$creadPrec :: ReadPrec PutRetentionPolicyResponse
readList :: ReadS [PutRetentionPolicyResponse]
$creadList :: ReadS [PutRetentionPolicyResponse]
readsPrec :: Int -> ReadS PutRetentionPolicyResponse
$creadsPrec :: Int -> ReadS PutRetentionPolicyResponse
Prelude.Read, Int -> PutRetentionPolicyResponse -> ShowS
[PutRetentionPolicyResponse] -> ShowS
PutRetentionPolicyResponse -> String
(Int -> PutRetentionPolicyResponse -> ShowS)
-> (PutRetentionPolicyResponse -> String)
-> ([PutRetentionPolicyResponse] -> ShowS)
-> Show PutRetentionPolicyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRetentionPolicyResponse] -> ShowS
$cshowList :: [PutRetentionPolicyResponse] -> ShowS
show :: PutRetentionPolicyResponse -> String
$cshow :: PutRetentionPolicyResponse -> String
showsPrec :: Int -> PutRetentionPolicyResponse -> ShowS
$cshowsPrec :: Int -> PutRetentionPolicyResponse -> ShowS
Prelude.Show, (forall x.
 PutRetentionPolicyResponse -> Rep PutRetentionPolicyResponse x)
-> (forall x.
    Rep PutRetentionPolicyResponse x -> PutRetentionPolicyResponse)
-> Generic PutRetentionPolicyResponse
forall x.
Rep PutRetentionPolicyResponse x -> PutRetentionPolicyResponse
forall x.
PutRetentionPolicyResponse -> Rep PutRetentionPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutRetentionPolicyResponse x -> PutRetentionPolicyResponse
$cfrom :: forall x.
PutRetentionPolicyResponse -> Rep PutRetentionPolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutRetentionPolicyResponse' 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.
newPutRetentionPolicyResponse ::
  PutRetentionPolicyResponse
newPutRetentionPolicyResponse :: PutRetentionPolicyResponse
newPutRetentionPolicyResponse =
  PutRetentionPolicyResponse
PutRetentionPolicyResponse'

instance Prelude.NFData PutRetentionPolicyResponse