{-# 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.StorageGateway.AddCache
-- 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)
--
-- Configures one or more gateway local disks as cache for a gateway. This
-- operation is only supported in the cached volume, tape, and file gateway
-- type (see
-- <https://docs.aws.amazon.com/storagegateway/latest/userguide/StorageGatewayConcepts.html How Storage Gateway works (architecture)>.
--
-- In the request, you specify the gateway Amazon Resource Name (ARN) to
-- which you want to add cache, and one or more disk IDs that you want to
-- configure as cache.
module Amazonka.StorageGateway.AddCache
  ( -- * Creating a Request
    AddCache (..),
    newAddCache,

    -- * Request Lenses
    addCache_gatewayARN,
    addCache_diskIds,

    -- * Destructuring the Response
    AddCacheResponse (..),
    newAddCacheResponse,

    -- * Response Lenses
    addCacheResponse_gatewayARN,
    addCacheResponse_httpStatus,
  )
where

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
import Amazonka.StorageGateway.Types

-- | /See:/ 'newAddCache' smart constructor.
data AddCache = AddCache'
  { AddCache -> Text
gatewayARN :: Prelude.Text,
    -- | An array of strings that identify disks that are to be configured as
    -- working storage. Each string has a minimum length of 1 and maximum
    -- length of 300. You can get the disk IDs from the ListLocalDisks API.
    AddCache -> [Text]
diskIds :: [Prelude.Text]
  }
  deriving (AddCache -> AddCache -> Bool
(AddCache -> AddCache -> Bool)
-> (AddCache -> AddCache -> Bool) -> Eq AddCache
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddCache -> AddCache -> Bool
$c/= :: AddCache -> AddCache -> Bool
== :: AddCache -> AddCache -> Bool
$c== :: AddCache -> AddCache -> Bool
Prelude.Eq, ReadPrec [AddCache]
ReadPrec AddCache
Int -> ReadS AddCache
ReadS [AddCache]
(Int -> ReadS AddCache)
-> ReadS [AddCache]
-> ReadPrec AddCache
-> ReadPrec [AddCache]
-> Read AddCache
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddCache]
$creadListPrec :: ReadPrec [AddCache]
readPrec :: ReadPrec AddCache
$creadPrec :: ReadPrec AddCache
readList :: ReadS [AddCache]
$creadList :: ReadS [AddCache]
readsPrec :: Int -> ReadS AddCache
$creadsPrec :: Int -> ReadS AddCache
Prelude.Read, Int -> AddCache -> ShowS
[AddCache] -> ShowS
AddCache -> String
(Int -> AddCache -> ShowS)
-> (AddCache -> String) -> ([AddCache] -> ShowS) -> Show AddCache
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddCache] -> ShowS
$cshowList :: [AddCache] -> ShowS
show :: AddCache -> String
$cshow :: AddCache -> String
showsPrec :: Int -> AddCache -> ShowS
$cshowsPrec :: Int -> AddCache -> ShowS
Prelude.Show, (forall x. AddCache -> Rep AddCache x)
-> (forall x. Rep AddCache x -> AddCache) -> Generic AddCache
forall x. Rep AddCache x -> AddCache
forall x. AddCache -> Rep AddCache x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AddCache x -> AddCache
$cfrom :: forall x. AddCache -> Rep AddCache x
Prelude.Generic)

-- |
-- Create a value of 'AddCache' 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:
--
-- 'gatewayARN', 'addCache_gatewayARN' - Undocumented member.
--
-- 'diskIds', 'addCache_diskIds' - An array of strings that identify disks that are to be configured as
-- working storage. Each string has a minimum length of 1 and maximum
-- length of 300. You can get the disk IDs from the ListLocalDisks API.
newAddCache ::
  -- | 'gatewayARN'
  Prelude.Text ->
  AddCache
newAddCache :: Text -> AddCache
newAddCache Text
pGatewayARN_ =
  AddCache' :: Text -> [Text] -> AddCache
AddCache'
    { $sel:gatewayARN:AddCache' :: Text
gatewayARN = Text
pGatewayARN_,
      $sel:diskIds:AddCache' :: [Text]
diskIds = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | Undocumented member.
addCache_gatewayARN :: Lens.Lens' AddCache Prelude.Text
addCache_gatewayARN :: (Text -> f Text) -> AddCache -> f AddCache
addCache_gatewayARN = (AddCache -> Text)
-> (AddCache -> Text -> AddCache)
-> Lens AddCache AddCache Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddCache' {Text
gatewayARN :: Text
$sel:gatewayARN:AddCache' :: AddCache -> Text
gatewayARN} -> Text
gatewayARN) (\s :: AddCache
s@AddCache' {} Text
a -> AddCache
s {$sel:gatewayARN:AddCache' :: Text
gatewayARN = Text
a} :: AddCache)

-- | An array of strings that identify disks that are to be configured as
-- working storage. Each string has a minimum length of 1 and maximum
-- length of 300. You can get the disk IDs from the ListLocalDisks API.
addCache_diskIds :: Lens.Lens' AddCache [Prelude.Text]
addCache_diskIds :: ([Text] -> f [Text]) -> AddCache -> f AddCache
addCache_diskIds = (AddCache -> [Text])
-> (AddCache -> [Text] -> AddCache)
-> Lens AddCache AddCache [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddCache' {[Text]
diskIds :: [Text]
$sel:diskIds:AddCache' :: AddCache -> [Text]
diskIds} -> [Text]
diskIds) (\s :: AddCache
s@AddCache' {} [Text]
a -> AddCache
s {$sel:diskIds:AddCache' :: [Text]
diskIds = [Text]
a} :: AddCache) (([Text] -> f [Text]) -> AddCache -> f AddCache)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> AddCache
-> f AddCache
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest AddCache where
  type AWSResponse AddCache = AddCacheResponse
  request :: AddCache -> Request AddCache
request = Service -> AddCache -> Request AddCache
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AddCache
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AddCache)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse AddCache))
-> Logger
-> Service
-> Proxy AddCache
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AddCache)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> AddCacheResponse
AddCacheResponse'
            (Maybe Text -> Int -> AddCacheResponse)
-> Either String (Maybe Text)
-> Either String (Int -> AddCacheResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"GatewayARN")
            Either String (Int -> AddCacheResponse)
-> Either String Int -> Either String AddCacheResponse
forall (f :: * -> *) a b. Applicative f => 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 AddCache

instance Prelude.NFData AddCache

instance Core.ToHeaders AddCache where
  toHeaders :: AddCache -> ResponseHeaders
toHeaders =
    ResponseHeaders -> AddCache -> 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
"StorageGateway_20130630.AddCache" ::
                          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 AddCache where
  toJSON :: AddCache -> Value
toJSON AddCache' {[Text]
Text
diskIds :: [Text]
gatewayARN :: Text
$sel:diskIds:AddCache' :: AddCache -> [Text]
$sel:gatewayARN:AddCache' :: AddCache -> 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
"GatewayARN" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
gatewayARN),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"DiskIds" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
diskIds)
          ]
      )

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

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

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

-- |
-- Create a value of 'AddCacheResponse' 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:
--
-- 'gatewayARN', 'addCacheResponse_gatewayARN' - Undocumented member.
--
-- 'httpStatus', 'addCacheResponse_httpStatus' - The response's http status code.
newAddCacheResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AddCacheResponse
newAddCacheResponse :: Int -> AddCacheResponse
newAddCacheResponse Int
pHttpStatus_ =
  AddCacheResponse' :: Maybe Text -> Int -> AddCacheResponse
AddCacheResponse'
    { $sel:gatewayARN:AddCacheResponse' :: Maybe Text
gatewayARN = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AddCacheResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Undocumented member.
addCacheResponse_gatewayARN :: Lens.Lens' AddCacheResponse (Prelude.Maybe Prelude.Text)
addCacheResponse_gatewayARN :: (Maybe Text -> f (Maybe Text))
-> AddCacheResponse -> f AddCacheResponse
addCacheResponse_gatewayARN = (AddCacheResponse -> Maybe Text)
-> (AddCacheResponse -> Maybe Text -> AddCacheResponse)
-> Lens AddCacheResponse AddCacheResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddCacheResponse' {Maybe Text
gatewayARN :: Maybe Text
$sel:gatewayARN:AddCacheResponse' :: AddCacheResponse -> Maybe Text
gatewayARN} -> Maybe Text
gatewayARN) (\s :: AddCacheResponse
s@AddCacheResponse' {} Maybe Text
a -> AddCacheResponse
s {$sel:gatewayARN:AddCacheResponse' :: Maybe Text
gatewayARN = Maybe Text
a} :: AddCacheResponse)

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

instance Prelude.NFData AddCacheResponse