{-# 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.MediaStore.PutLifecyclePolicy
-- 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)
--
-- Writes an object lifecycle policy to a container. If the container
-- already has an object lifecycle policy, the service replaces the
-- existing policy with the new policy. It takes up to 20 minutes for the
-- change to take effect.
--
-- For information about how to construct an object lifecycle policy, see
-- <https://docs.aws.amazon.com/mediastore/latest/ug/policies-object-lifecycle-components.html Components of an Object Lifecycle Policy>.
module Amazonka.MediaStore.PutLifecyclePolicy
  ( -- * Creating a Request
    PutLifecyclePolicy (..),
    newPutLifecyclePolicy,

    -- * Request Lenses
    putLifecyclePolicy_containerName,
    putLifecyclePolicy_lifecyclePolicy,

    -- * Destructuring the Response
    PutLifecyclePolicyResponse (..),
    newPutLifecyclePolicyResponse,

    -- * Response Lenses
    putLifecyclePolicyResponse_httpStatus,
  )
where

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

-- | /See:/ 'newPutLifecyclePolicy' smart constructor.
data PutLifecyclePolicy = PutLifecyclePolicy'
  { -- | The name of the container that you want to assign the object lifecycle
    -- policy to.
    PutLifecyclePolicy -> Text
containerName :: Prelude.Text,
    -- | The object lifecycle policy to apply to the container.
    PutLifecyclePolicy -> Text
lifecyclePolicy :: Prelude.Text
  }
  deriving (PutLifecyclePolicy -> PutLifecyclePolicy -> Bool
(PutLifecyclePolicy -> PutLifecyclePolicy -> Bool)
-> (PutLifecyclePolicy -> PutLifecyclePolicy -> Bool)
-> Eq PutLifecyclePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutLifecyclePolicy -> PutLifecyclePolicy -> Bool
$c/= :: PutLifecyclePolicy -> PutLifecyclePolicy -> Bool
== :: PutLifecyclePolicy -> PutLifecyclePolicy -> Bool
$c== :: PutLifecyclePolicy -> PutLifecyclePolicy -> Bool
Prelude.Eq, ReadPrec [PutLifecyclePolicy]
ReadPrec PutLifecyclePolicy
Int -> ReadS PutLifecyclePolicy
ReadS [PutLifecyclePolicy]
(Int -> ReadS PutLifecyclePolicy)
-> ReadS [PutLifecyclePolicy]
-> ReadPrec PutLifecyclePolicy
-> ReadPrec [PutLifecyclePolicy]
-> Read PutLifecyclePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutLifecyclePolicy]
$creadListPrec :: ReadPrec [PutLifecyclePolicy]
readPrec :: ReadPrec PutLifecyclePolicy
$creadPrec :: ReadPrec PutLifecyclePolicy
readList :: ReadS [PutLifecyclePolicy]
$creadList :: ReadS [PutLifecyclePolicy]
readsPrec :: Int -> ReadS PutLifecyclePolicy
$creadsPrec :: Int -> ReadS PutLifecyclePolicy
Prelude.Read, Int -> PutLifecyclePolicy -> ShowS
[PutLifecyclePolicy] -> ShowS
PutLifecyclePolicy -> String
(Int -> PutLifecyclePolicy -> ShowS)
-> (PutLifecyclePolicy -> String)
-> ([PutLifecyclePolicy] -> ShowS)
-> Show PutLifecyclePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutLifecyclePolicy] -> ShowS
$cshowList :: [PutLifecyclePolicy] -> ShowS
show :: PutLifecyclePolicy -> String
$cshow :: PutLifecyclePolicy -> String
showsPrec :: Int -> PutLifecyclePolicy -> ShowS
$cshowsPrec :: Int -> PutLifecyclePolicy -> ShowS
Prelude.Show, (forall x. PutLifecyclePolicy -> Rep PutLifecyclePolicy x)
-> (forall x. Rep PutLifecyclePolicy x -> PutLifecyclePolicy)
-> Generic PutLifecyclePolicy
forall x. Rep PutLifecyclePolicy x -> PutLifecyclePolicy
forall x. PutLifecyclePolicy -> Rep PutLifecyclePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutLifecyclePolicy x -> PutLifecyclePolicy
$cfrom :: forall x. PutLifecyclePolicy -> Rep PutLifecyclePolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutLifecyclePolicy' 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:
--
-- 'containerName', 'putLifecyclePolicy_containerName' - The name of the container that you want to assign the object lifecycle
-- policy to.
--
-- 'lifecyclePolicy', 'putLifecyclePolicy_lifecyclePolicy' - The object lifecycle policy to apply to the container.
newPutLifecyclePolicy ::
  -- | 'containerName'
  Prelude.Text ->
  -- | 'lifecyclePolicy'
  Prelude.Text ->
  PutLifecyclePolicy
newPutLifecyclePolicy :: Text -> Text -> PutLifecyclePolicy
newPutLifecyclePolicy
  Text
pContainerName_
  Text
pLifecyclePolicy_ =
    PutLifecyclePolicy' :: Text -> Text -> PutLifecyclePolicy
PutLifecyclePolicy'
      { $sel:containerName:PutLifecyclePolicy' :: Text
containerName =
          Text
pContainerName_,
        $sel:lifecyclePolicy:PutLifecyclePolicy' :: Text
lifecyclePolicy = Text
pLifecyclePolicy_
      }

-- | The name of the container that you want to assign the object lifecycle
-- policy to.
putLifecyclePolicy_containerName :: Lens.Lens' PutLifecyclePolicy Prelude.Text
putLifecyclePolicy_containerName :: (Text -> f Text) -> PutLifecyclePolicy -> f PutLifecyclePolicy
putLifecyclePolicy_containerName = (PutLifecyclePolicy -> Text)
-> (PutLifecyclePolicy -> Text -> PutLifecyclePolicy)
-> Lens PutLifecyclePolicy PutLifecyclePolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutLifecyclePolicy' {Text
containerName :: Text
$sel:containerName:PutLifecyclePolicy' :: PutLifecyclePolicy -> Text
containerName} -> Text
containerName) (\s :: PutLifecyclePolicy
s@PutLifecyclePolicy' {} Text
a -> PutLifecyclePolicy
s {$sel:containerName:PutLifecyclePolicy' :: Text
containerName = Text
a} :: PutLifecyclePolicy)

-- | The object lifecycle policy to apply to the container.
putLifecyclePolicy_lifecyclePolicy :: Lens.Lens' PutLifecyclePolicy Prelude.Text
putLifecyclePolicy_lifecyclePolicy :: (Text -> f Text) -> PutLifecyclePolicy -> f PutLifecyclePolicy
putLifecyclePolicy_lifecyclePolicy = (PutLifecyclePolicy -> Text)
-> (PutLifecyclePolicy -> Text -> PutLifecyclePolicy)
-> Lens PutLifecyclePolicy PutLifecyclePolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutLifecyclePolicy' {Text
lifecyclePolicy :: Text
$sel:lifecyclePolicy:PutLifecyclePolicy' :: PutLifecyclePolicy -> Text
lifecyclePolicy} -> Text
lifecyclePolicy) (\s :: PutLifecyclePolicy
s@PutLifecyclePolicy' {} Text
a -> PutLifecyclePolicy
s {$sel:lifecyclePolicy:PutLifecyclePolicy' :: Text
lifecyclePolicy = Text
a} :: PutLifecyclePolicy)

instance Core.AWSRequest PutLifecyclePolicy where
  type
    AWSResponse PutLifecyclePolicy =
      PutLifecyclePolicyResponse
  request :: PutLifecyclePolicy -> Request PutLifecyclePolicy
request = Service -> PutLifecyclePolicy -> Request PutLifecyclePolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutLifecyclePolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutLifecyclePolicy)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse PutLifecyclePolicy))
-> Logger
-> Service
-> Proxy PutLifecyclePolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutLifecyclePolicy)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> PutLifecyclePolicyResponse
PutLifecyclePolicyResponse'
            (Int -> PutLifecyclePolicyResponse)
-> Either String Int -> Either String PutLifecyclePolicyResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable PutLifecyclePolicy

instance Prelude.NFData PutLifecyclePolicy

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

instance Core.ToJSON PutLifecyclePolicy where
  toJSON :: PutLifecyclePolicy -> Value
toJSON PutLifecyclePolicy' {Text
lifecyclePolicy :: Text
containerName :: Text
$sel:lifecyclePolicy:PutLifecyclePolicy' :: PutLifecyclePolicy -> Text
$sel:containerName:PutLifecyclePolicy' :: PutLifecyclePolicy -> 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
"ContainerName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
containerName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"LifecyclePolicy" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
lifecyclePolicy)
          ]
      )

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

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

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

-- |
-- Create a value of 'PutLifecyclePolicyResponse' 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:
--
-- 'httpStatus', 'putLifecyclePolicyResponse_httpStatus' - The response's http status code.
newPutLifecyclePolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutLifecyclePolicyResponse
newPutLifecyclePolicyResponse :: Int -> PutLifecyclePolicyResponse
newPutLifecyclePolicyResponse Int
pHttpStatus_ =
  PutLifecyclePolicyResponse' :: Int -> PutLifecyclePolicyResponse
PutLifecyclePolicyResponse'
    { $sel:httpStatus:PutLifecyclePolicyResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | The response's http status code.
putLifecyclePolicyResponse_httpStatus :: Lens.Lens' PutLifecyclePolicyResponse Prelude.Int
putLifecyclePolicyResponse_httpStatus :: (Int -> f Int)
-> PutLifecyclePolicyResponse -> f PutLifecyclePolicyResponse
putLifecyclePolicyResponse_httpStatus = (PutLifecyclePolicyResponse -> Int)
-> (PutLifecyclePolicyResponse
    -> Int -> PutLifecyclePolicyResponse)
-> Lens
     PutLifecyclePolicyResponse PutLifecyclePolicyResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutLifecyclePolicyResponse' {Int
httpStatus :: Int
$sel:httpStatus:PutLifecyclePolicyResponse' :: PutLifecyclePolicyResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: PutLifecyclePolicyResponse
s@PutLifecyclePolicyResponse' {} Int
a -> PutLifecyclePolicyResponse
s {$sel:httpStatus:PutLifecyclePolicyResponse' :: Int
httpStatus = Int
a} :: PutLifecyclePolicyResponse)

instance Prelude.NFData PutLifecyclePolicyResponse