{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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' {$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 :: Lens' CreateAddress Address
createAddress_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 :: (Service -> Service) -> CreateAddress -> Request CreateAddress
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CreateAddress
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateAddress)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> CreateAddressResponse
CreateAddressResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"AddressId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateAddress where
  hashWithSalt :: Int -> CreateAddress -> Int
hashWithSalt Int
_salt CreateAddress' {Address
address :: Address
$sel:address:CreateAddress' :: CreateAddress -> Address
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Address
address

instance Prelude.NFData CreateAddress where
  rnf :: CreateAddress -> ()
rnf CreateAddress' {Address
address :: Address
$sel:address:CreateAddress' :: CreateAddress -> Address
..} = forall a. NFData a => a -> ()
Prelude.rnf Address
address

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

instance Data.ToJSON CreateAddress where
  toJSON :: CreateAddress -> Value
toJSON CreateAddress' {Address
address :: Address
$sel:address:CreateAddress' :: CreateAddress -> Address
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"Address" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Address
address)]
      )

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

instance Data.ToQuery CreateAddress where
  toQuery :: CreateAddress -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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. 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'
    { $sel:addressId:CreateAddressResponse' :: Maybe Text
addressId = 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 :: Lens' CreateAddressResponse (Maybe Text)
createAddressResponse_addressId = 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 :: Lens' CreateAddressResponse Int
createAddressResponse_httpStatus = 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 where
  rnf :: CreateAddressResponse -> ()
rnf CreateAddressResponse' {Int
Maybe Text
httpStatus :: Int
addressId :: Maybe Text
$sel:httpStatus:CreateAddressResponse' :: CreateAddressResponse -> Int
$sel:addressId:CreateAddressResponse' :: CreateAddressResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
addressId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus