{-# 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.NetworkManager.CreateSite
-- 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 a new site in a global network.
module Amazonka.NetworkManager.CreateSite
  ( -- * Creating a Request
    CreateSite (..),
    newCreateSite,

    -- * Request Lenses
    createSite_location,
    createSite_description,
    createSite_tags,
    createSite_globalNetworkId,

    -- * Destructuring the Response
    CreateSiteResponse (..),
    newCreateSiteResponse,

    -- * Response Lenses
    createSiteResponse_site,
    createSiteResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateSite' smart constructor.
data CreateSite = CreateSite'
  { -- | The site location. This information is used for visualization in the
    -- Network Manager console. If you specify the address, the latitude and
    -- longitude are automatically calculated.
    --
    -- -   @Address@: The physical address of the site.
    --
    -- -   @Latitude@: The latitude of the site.
    --
    -- -   @Longitude@: The longitude of the site.
    CreateSite -> Maybe (Sensitive Location)
location :: Prelude.Maybe (Core.Sensitive Location),
    -- | A description of your site.
    --
    -- Length Constraints: Maximum length of 256 characters.
    CreateSite -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The tags to apply to the resource during creation.
    CreateSite -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The ID of the global network.
    CreateSite -> Text
globalNetworkId :: Prelude.Text
  }
  deriving (CreateSite -> CreateSite -> Bool
(CreateSite -> CreateSite -> Bool)
-> (CreateSite -> CreateSite -> Bool) -> Eq CreateSite
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateSite -> CreateSite -> Bool
$c/= :: CreateSite -> CreateSite -> Bool
== :: CreateSite -> CreateSite -> Bool
$c== :: CreateSite -> CreateSite -> Bool
Prelude.Eq, Int -> CreateSite -> ShowS
[CreateSite] -> ShowS
CreateSite -> String
(Int -> CreateSite -> ShowS)
-> (CreateSite -> String)
-> ([CreateSite] -> ShowS)
-> Show CreateSite
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateSite] -> ShowS
$cshowList :: [CreateSite] -> ShowS
show :: CreateSite -> String
$cshow :: CreateSite -> String
showsPrec :: Int -> CreateSite -> ShowS
$cshowsPrec :: Int -> CreateSite -> ShowS
Prelude.Show, (forall x. CreateSite -> Rep CreateSite x)
-> (forall x. Rep CreateSite x -> CreateSite) -> Generic CreateSite
forall x. Rep CreateSite x -> CreateSite
forall x. CreateSite -> Rep CreateSite x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateSite x -> CreateSite
$cfrom :: forall x. CreateSite -> Rep CreateSite x
Prelude.Generic)

-- |
-- Create a value of 'CreateSite' 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:
--
-- 'location', 'createSite_location' - The site location. This information is used for visualization in the
-- Network Manager console. If you specify the address, the latitude and
-- longitude are automatically calculated.
--
-- -   @Address@: The physical address of the site.
--
-- -   @Latitude@: The latitude of the site.
--
-- -   @Longitude@: The longitude of the site.
--
-- 'description', 'createSite_description' - A description of your site.
--
-- Length Constraints: Maximum length of 256 characters.
--
-- 'tags', 'createSite_tags' - The tags to apply to the resource during creation.
--
-- 'globalNetworkId', 'createSite_globalNetworkId' - The ID of the global network.
newCreateSite ::
  -- | 'globalNetworkId'
  Prelude.Text ->
  CreateSite
newCreateSite :: Text -> CreateSite
newCreateSite Text
pGlobalNetworkId_ =
  CreateSite' :: Maybe (Sensitive Location)
-> Maybe Text -> Maybe [Tag] -> Text -> CreateSite
CreateSite'
    { $sel:location:CreateSite' :: Maybe (Sensitive Location)
location = Maybe (Sensitive Location)
forall a. Maybe a
Prelude.Nothing,
      $sel:description:CreateSite' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateSite' :: Maybe [Tag]
tags = Maybe [Tag]
forall a. Maybe a
Prelude.Nothing,
      $sel:globalNetworkId:CreateSite' :: Text
globalNetworkId = Text
pGlobalNetworkId_
    }

-- | The site location. This information is used for visualization in the
-- Network Manager console. If you specify the address, the latitude and
-- longitude are automatically calculated.
--
-- -   @Address@: The physical address of the site.
--
-- -   @Latitude@: The latitude of the site.
--
-- -   @Longitude@: The longitude of the site.
createSite_location :: Lens.Lens' CreateSite (Prelude.Maybe Location)
createSite_location :: (Maybe Location -> f (Maybe Location))
-> CreateSite -> f CreateSite
createSite_location = (CreateSite -> Maybe (Sensitive Location))
-> (CreateSite -> Maybe (Sensitive Location) -> CreateSite)
-> Lens
     CreateSite
     CreateSite
     (Maybe (Sensitive Location))
     (Maybe (Sensitive Location))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSite' {Maybe (Sensitive Location)
location :: Maybe (Sensitive Location)
$sel:location:CreateSite' :: CreateSite -> Maybe (Sensitive Location)
location} -> Maybe (Sensitive Location)
location) (\s :: CreateSite
s@CreateSite' {} Maybe (Sensitive Location)
a -> CreateSite
s {$sel:location:CreateSite' :: Maybe (Sensitive Location)
location = Maybe (Sensitive Location)
a} :: CreateSite) ((Maybe (Sensitive Location) -> f (Maybe (Sensitive Location)))
 -> CreateSite -> f CreateSite)
-> ((Maybe Location -> f (Maybe Location))
    -> Maybe (Sensitive Location) -> f (Maybe (Sensitive Location)))
-> (Maybe Location -> f (Maybe Location))
-> CreateSite
-> f CreateSite
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (Sensitive Location) (Sensitive Location) Location Location
-> Iso
     (Maybe (Sensitive Location))
     (Maybe (Sensitive Location))
     (Maybe Location)
     (Maybe Location)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso (Sensitive Location) (Sensitive Location) Location Location
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | A description of your site.
--
-- Length Constraints: Maximum length of 256 characters.
createSite_description :: Lens.Lens' CreateSite (Prelude.Maybe Prelude.Text)
createSite_description :: (Maybe Text -> f (Maybe Text)) -> CreateSite -> f CreateSite
createSite_description = (CreateSite -> Maybe Text)
-> (CreateSite -> Maybe Text -> CreateSite)
-> Lens CreateSite CreateSite (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSite' {Maybe Text
description :: Maybe Text
$sel:description:CreateSite' :: CreateSite -> Maybe Text
description} -> Maybe Text
description) (\s :: CreateSite
s@CreateSite' {} Maybe Text
a -> CreateSite
s {$sel:description:CreateSite' :: Maybe Text
description = Maybe Text
a} :: CreateSite)

-- | The tags to apply to the resource during creation.
createSite_tags :: Lens.Lens' CreateSite (Prelude.Maybe [Tag])
createSite_tags :: (Maybe [Tag] -> f (Maybe [Tag])) -> CreateSite -> f CreateSite
createSite_tags = (CreateSite -> Maybe [Tag])
-> (CreateSite -> Maybe [Tag] -> CreateSite)
-> Lens CreateSite CreateSite (Maybe [Tag]) (Maybe [Tag])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSite' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateSite' :: CreateSite -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateSite
s@CreateSite' {} Maybe [Tag]
a -> CreateSite
s {$sel:tags:CreateSite' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateSite) ((Maybe [Tag] -> f (Maybe [Tag])) -> CreateSite -> f CreateSite)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateSite
-> f CreateSite
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Tag] [Tag] [Tag] [Tag]
-> Iso (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Tag] [Tag] [Tag] [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ID of the global network.
createSite_globalNetworkId :: Lens.Lens' CreateSite Prelude.Text
createSite_globalNetworkId :: (Text -> f Text) -> CreateSite -> f CreateSite
createSite_globalNetworkId = (CreateSite -> Text)
-> (CreateSite -> Text -> CreateSite)
-> Lens CreateSite CreateSite Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSite' {Text
globalNetworkId :: Text
$sel:globalNetworkId:CreateSite' :: CreateSite -> Text
globalNetworkId} -> Text
globalNetworkId) (\s :: CreateSite
s@CreateSite' {} Text
a -> CreateSite
s {$sel:globalNetworkId:CreateSite' :: Text
globalNetworkId = Text
a} :: CreateSite)

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

instance Prelude.NFData CreateSite

instance Core.ToHeaders CreateSite where
  toHeaders :: CreateSite -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateSite -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 CreateSite where
  toJSON :: CreateSite -> Value
toJSON CreateSite' {Maybe [Tag]
Maybe Text
Maybe (Sensitive Location)
Text
globalNetworkId :: Text
tags :: Maybe [Tag]
description :: Maybe Text
location :: Maybe (Sensitive Location)
$sel:globalNetworkId:CreateSite' :: CreateSite -> Text
$sel:tags:CreateSite' :: CreateSite -> Maybe [Tag]
$sel:description:CreateSite' :: CreateSite -> Maybe Text
$sel:location:CreateSite' :: CreateSite -> Maybe (Sensitive Location)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Location" Text -> Sensitive Location -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Sensitive Location -> Pair)
-> Maybe (Sensitive Location) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (Sensitive Location)
location,
            (Text
"Description" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            (Text
"Tags" Text -> [Tag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Tag] -> Pair) -> Maybe [Tag] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags
          ]
      )

instance Core.ToPath CreateSite where
  toPath :: CreateSite -> ByteString
toPath CreateSite' {Maybe [Tag]
Maybe Text
Maybe (Sensitive Location)
Text
globalNetworkId :: Text
tags :: Maybe [Tag]
description :: Maybe Text
location :: Maybe (Sensitive Location)
$sel:globalNetworkId:CreateSite' :: CreateSite -> Text
$sel:tags:CreateSite' :: CreateSite -> Maybe [Tag]
$sel:description:CreateSite' :: CreateSite -> Maybe Text
$sel:location:CreateSite' :: CreateSite -> Maybe (Sensitive Location)
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/global-networks/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
globalNetworkId,
        ByteString
"/sites"
      ]

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

-- | /See:/ 'newCreateSiteResponse' smart constructor.
data CreateSiteResponse = CreateSiteResponse'
  { -- | Information about the site.
    CreateSiteResponse -> Maybe Site
site :: Prelude.Maybe Site,
    -- | The response's http status code.
    CreateSiteResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateSiteResponse -> CreateSiteResponse -> Bool
(CreateSiteResponse -> CreateSiteResponse -> Bool)
-> (CreateSiteResponse -> CreateSiteResponse -> Bool)
-> Eq CreateSiteResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateSiteResponse -> CreateSiteResponse -> Bool
$c/= :: CreateSiteResponse -> CreateSiteResponse -> Bool
== :: CreateSiteResponse -> CreateSiteResponse -> Bool
$c== :: CreateSiteResponse -> CreateSiteResponse -> Bool
Prelude.Eq, Int -> CreateSiteResponse -> ShowS
[CreateSiteResponse] -> ShowS
CreateSiteResponse -> String
(Int -> CreateSiteResponse -> ShowS)
-> (CreateSiteResponse -> String)
-> ([CreateSiteResponse] -> ShowS)
-> Show CreateSiteResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateSiteResponse] -> ShowS
$cshowList :: [CreateSiteResponse] -> ShowS
show :: CreateSiteResponse -> String
$cshow :: CreateSiteResponse -> String
showsPrec :: Int -> CreateSiteResponse -> ShowS
$cshowsPrec :: Int -> CreateSiteResponse -> ShowS
Prelude.Show, (forall x. CreateSiteResponse -> Rep CreateSiteResponse x)
-> (forall x. Rep CreateSiteResponse x -> CreateSiteResponse)
-> Generic CreateSiteResponse
forall x. Rep CreateSiteResponse x -> CreateSiteResponse
forall x. CreateSiteResponse -> Rep CreateSiteResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateSiteResponse x -> CreateSiteResponse
$cfrom :: forall x. CreateSiteResponse -> Rep CreateSiteResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateSiteResponse' 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:
--
-- 'site', 'createSiteResponse_site' - Information about the site.
--
-- 'httpStatus', 'createSiteResponse_httpStatus' - The response's http status code.
newCreateSiteResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateSiteResponse
newCreateSiteResponse :: Int -> CreateSiteResponse
newCreateSiteResponse Int
pHttpStatus_ =
  CreateSiteResponse' :: Maybe Site -> Int -> CreateSiteResponse
CreateSiteResponse'
    { $sel:site:CreateSiteResponse' :: Maybe Site
site = Maybe Site
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateSiteResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the site.
createSiteResponse_site :: Lens.Lens' CreateSiteResponse (Prelude.Maybe Site)
createSiteResponse_site :: (Maybe Site -> f (Maybe Site))
-> CreateSiteResponse -> f CreateSiteResponse
createSiteResponse_site = (CreateSiteResponse -> Maybe Site)
-> (CreateSiteResponse -> Maybe Site -> CreateSiteResponse)
-> Lens
     CreateSiteResponse CreateSiteResponse (Maybe Site) (Maybe Site)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSiteResponse' {Maybe Site
site :: Maybe Site
$sel:site:CreateSiteResponse' :: CreateSiteResponse -> Maybe Site
site} -> Maybe Site
site) (\s :: CreateSiteResponse
s@CreateSiteResponse' {} Maybe Site
a -> CreateSiteResponse
s {$sel:site:CreateSiteResponse' :: Maybe Site
site = Maybe Site
a} :: CreateSiteResponse)

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

instance Prelude.NFData CreateSiteResponse