{-# 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.Snowball.CreateAddress
-- 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)
--
-- Creates an address for a Snow device to be shipped to. In most regions,
-- addresses are validated at the time of creation. The address you provide
-- must be located within the serviceable area of your region. If the
-- address is invalid or unsupported, then an exception is thrown.
module Amazonka.Snowball.CreateAddress
  ( -- * Creating a Request
    CreateAddress (..),
    newCreateAddress,

    -- * Request Lenses
    createAddress_address,

    -- * Destructuring the Response
    CreateAddressResponse (..),
    newCreateAddressResponse,

    -- * Response Lenses
    createAddressResponse_addressId,
    createAddressResponse_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.Snowball.Types

-- | /See:/ 'newCreateAddress' smart constructor.
data CreateAddress = CreateAddress'
  { -- | The address that you want the Snow device shipped to.
    CreateAddress -> Address
address :: Address
  }
  deriving (CreateAddress -> CreateAddress -> Bool
(CreateAddress -> CreateAddress -> Bool)
-> (CreateAddress -> CreateAddress -> Bool) -> Eq CreateAddress
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateAddress -> CreateAddress -> Bool
$c/= :: CreateAddress -> CreateAddress -> Bool
== :: CreateAddress -> CreateAddress -> Bool
$c== :: CreateAddress -> CreateAddress -> Bool
Prelude.Eq, ReadPrec [CreateAddress]
ReadPrec CreateAddress
Int -> ReadS CreateAddress
ReadS [CreateAddress]
(Int -> ReadS CreateAddress)
-> ReadS [CreateAddress]
-> ReadPrec CreateAddress
-> ReadPrec [CreateAddress]
-> Read CreateAddress
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateAddress]
$creadListPrec :: ReadPrec [CreateAddress]
readPrec :: ReadPrec CreateAddress
$creadPrec :: ReadPrec CreateAddress
readList :: ReadS [CreateAddress]
$creadList :: ReadS [CreateAddress]
readsPrec :: Int -> ReadS CreateAddress
$creadsPrec :: Int -> ReadS CreateAddress
Prelude.Read, Int -> CreateAddress -> ShowS
[CreateAddress] -> ShowS
CreateAddress -> String
(Int -> CreateAddress -> ShowS)
-> (CreateAddress -> String)
-> ([CreateAddress] -> ShowS)
-> Show CreateAddress
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateAddress] -> ShowS
$cshowList :: [CreateAddress] -> ShowS
show :: CreateAddress -> String
$cshow :: CreateAddress -> String
showsPrec :: Int -> CreateAddress -> ShowS
$cshowsPrec :: Int -> CreateAddress -> ShowS
Prelude.Show, (forall x. CreateAddress -> Rep CreateAddress x)
-> (forall x. Rep CreateAddress x -> CreateAddress)
-> Generic CreateAddress
forall x. Rep CreateAddress x -> CreateAddress
forall x. CreateAddress -> Rep CreateAddress x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateAddress x -> CreateAddress
$cfrom :: forall x. CreateAddress -> Rep CreateAddress x
Prelude.Generic)

-- |
-- Create a value of 'CreateAddress' 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:
--
-- 'address', 'createAddress_address' - The address that you want the Snow device shipped to.
newCreateAddress ::
  -- | 'address'
  Address ->
  CreateAddress
newCreateAddress :: Address -> CreateAddress
newCreateAddress Address
pAddress_ =
  CreateAddress' :: Address -> CreateAddress
CreateAddress' {$sel:address:CreateAddress' :: Address
address = Address
pAddress_}

-- | The address that you want the Snow device shipped to.
createAddress_address :: Lens.Lens' CreateAddress Address
createAddress_address :: (Address -> f Address) -> CreateAddress -> f CreateAddress
createAddress_address = (CreateAddress -> Address)
-> (CreateAddress -> Address -> CreateAddress)
-> Lens CreateAddress CreateAddress Address Address
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAddress' {Address
address :: Address
$sel:address:CreateAddress' :: CreateAddress -> Address
address} -> Address
address) (\s :: CreateAddress
s@CreateAddress' {} Address
a -> CreateAddress
s {$sel:address:CreateAddress' :: Address
address = Address
a} :: CreateAddress)

instance Core.AWSRequest CreateAddress where
  type
    AWSResponse CreateAddress =
      CreateAddressResponse
  request :: CreateAddress -> Request CreateAddress
request = Service -> CreateAddress -> Request CreateAddress
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateAddress
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateAddress)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateAddress))
-> Logger
-> Service
-> Proxy CreateAddress
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateAddress)))
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 -> CreateAddressResponse
CreateAddressResponse'
            (Maybe Text -> Int -> CreateAddressResponse)
-> Either String (Maybe Text)
-> Either String (Int -> CreateAddressResponse)
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
"AddressId")
            Either String (Int -> CreateAddressResponse)
-> Either String Int -> Either String CreateAddressResponse
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 CreateAddress

instance Prelude.NFData CreateAddress

instance Core.ToHeaders CreateAddress where
  toHeaders :: CreateAddress -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateAddress -> 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
"AWSIESnowballJobManagementService.CreateAddress" ::
                          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 CreateAddress where
  toJSON :: CreateAddress -> Value
toJSON CreateAddress' {Address
address :: Address
$sel:address:CreateAddress' :: CreateAddress -> Address
..} =
    [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
"Address" Text -> Address -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Address
address)]
      )

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

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

-- | /See:/ 'newCreateAddressResponse' smart constructor.
data CreateAddressResponse = CreateAddressResponse'
  { -- | The automatically generated ID for a specific address. You\'ll use this
    -- ID when you create a job to specify which address you want the Snow
    -- device for that job shipped to.
    CreateAddressResponse -> Maybe Text
addressId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CreateAddressResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateAddressResponse -> CreateAddressResponse -> Bool
(CreateAddressResponse -> CreateAddressResponse -> Bool)
-> (CreateAddressResponse -> CreateAddressResponse -> Bool)
-> Eq CreateAddressResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateAddressResponse -> CreateAddressResponse -> Bool
$c/= :: CreateAddressResponse -> CreateAddressResponse -> Bool
== :: CreateAddressResponse -> CreateAddressResponse -> Bool
$c== :: CreateAddressResponse -> CreateAddressResponse -> Bool
Prelude.Eq, ReadPrec [CreateAddressResponse]
ReadPrec CreateAddressResponse
Int -> ReadS CreateAddressResponse
ReadS [CreateAddressResponse]
(Int -> ReadS CreateAddressResponse)
-> ReadS [CreateAddressResponse]
-> ReadPrec CreateAddressResponse
-> ReadPrec [CreateAddressResponse]
-> Read CreateAddressResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateAddressResponse]
$creadListPrec :: ReadPrec [CreateAddressResponse]
readPrec :: ReadPrec CreateAddressResponse
$creadPrec :: ReadPrec CreateAddressResponse
readList :: ReadS [CreateAddressResponse]
$creadList :: ReadS [CreateAddressResponse]
readsPrec :: Int -> ReadS CreateAddressResponse
$creadsPrec :: Int -> ReadS CreateAddressResponse
Prelude.Read, Int -> CreateAddressResponse -> ShowS
[CreateAddressResponse] -> ShowS
CreateAddressResponse -> String
(Int -> CreateAddressResponse -> ShowS)
-> (CreateAddressResponse -> String)
-> ([CreateAddressResponse] -> ShowS)
-> Show CreateAddressResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateAddressResponse] -> ShowS
$cshowList :: [CreateAddressResponse] -> ShowS
show :: CreateAddressResponse -> String
$cshow :: CreateAddressResponse -> String
showsPrec :: Int -> CreateAddressResponse -> ShowS
$cshowsPrec :: Int -> CreateAddressResponse -> ShowS
Prelude.Show, (forall x. CreateAddressResponse -> Rep CreateAddressResponse x)
-> (forall x. Rep CreateAddressResponse x -> CreateAddressResponse)
-> Generic CreateAddressResponse
forall x. Rep CreateAddressResponse x -> CreateAddressResponse
forall x. CreateAddressResponse -> Rep CreateAddressResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateAddressResponse x -> CreateAddressResponse
$cfrom :: forall x. CreateAddressResponse -> Rep CreateAddressResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateAddressResponse' 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:
--
-- 'addressId', 'createAddressResponse_addressId' - The automatically generated ID for a specific address. You\'ll use this
-- ID when you create a job to specify which address you want the Snow
-- device for that job shipped to.
--
-- 'httpStatus', 'createAddressResponse_httpStatus' - The response's http status code.
newCreateAddressResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateAddressResponse
newCreateAddressResponse :: Int -> CreateAddressResponse
newCreateAddressResponse Int
pHttpStatus_ =
  CreateAddressResponse' :: Maybe Text -> Int -> CreateAddressResponse
CreateAddressResponse'
    { $sel:addressId:CreateAddressResponse' :: Maybe Text
addressId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateAddressResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The automatically generated ID for a specific address. You\'ll use this
-- ID when you create a job to specify which address you want the Snow
-- device for that job shipped to.
createAddressResponse_addressId :: Lens.Lens' CreateAddressResponse (Prelude.Maybe Prelude.Text)
createAddressResponse_addressId :: (Maybe Text -> f (Maybe Text))
-> CreateAddressResponse -> f CreateAddressResponse
createAddressResponse_addressId = (CreateAddressResponse -> Maybe Text)
-> (CreateAddressResponse -> Maybe Text -> CreateAddressResponse)
-> Lens
     CreateAddressResponse
     CreateAddressResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAddressResponse' {Maybe Text
addressId :: Maybe Text
$sel:addressId:CreateAddressResponse' :: CreateAddressResponse -> Maybe Text
addressId} -> Maybe Text
addressId) (\s :: CreateAddressResponse
s@CreateAddressResponse' {} Maybe Text
a -> CreateAddressResponse
s {$sel:addressId:CreateAddressResponse' :: Maybe Text
addressId = Maybe Text
a} :: CreateAddressResponse)

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

instance Prelude.NFData CreateAddressResponse