{-# 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.GroundStation.CreateConfig
-- 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 @Config@ with the specified @configData@ parameters.
--
-- Only one type of @configData@ can be specified.
module Amazonka.GroundStation.CreateConfig
  ( -- * Creating a Request
    CreateConfig (..),
    newCreateConfig,

    -- * Request Lenses
    createConfig_tags,
    createConfig_configData,
    createConfig_name,

    -- * Destructuring the Response
    ConfigIdResponse (..),
    newConfigIdResponse,

    -- * Response Lenses
    configIdResponse_configArn,
    configIdResponse_configId,
    configIdResponse_configType,
  )
where

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

-- |
--
-- /See:/ 'newCreateConfig' smart constructor.
data CreateConfig = CreateConfig'
  { -- | Tags assigned to a @Config@.
    CreateConfig -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | Parameters of a @Config@.
    CreateConfig -> ConfigTypeData
configData :: ConfigTypeData,
    -- | Name of a @Config@.
    CreateConfig -> Text
name :: Prelude.Text
  }
  deriving (CreateConfig -> CreateConfig -> Bool
(CreateConfig -> CreateConfig -> Bool)
-> (CreateConfig -> CreateConfig -> Bool) -> Eq CreateConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateConfig -> CreateConfig -> Bool
$c/= :: CreateConfig -> CreateConfig -> Bool
== :: CreateConfig -> CreateConfig -> Bool
$c== :: CreateConfig -> CreateConfig -> Bool
Prelude.Eq, ReadPrec [CreateConfig]
ReadPrec CreateConfig
Int -> ReadS CreateConfig
ReadS [CreateConfig]
(Int -> ReadS CreateConfig)
-> ReadS [CreateConfig]
-> ReadPrec CreateConfig
-> ReadPrec [CreateConfig]
-> Read CreateConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateConfig]
$creadListPrec :: ReadPrec [CreateConfig]
readPrec :: ReadPrec CreateConfig
$creadPrec :: ReadPrec CreateConfig
readList :: ReadS [CreateConfig]
$creadList :: ReadS [CreateConfig]
readsPrec :: Int -> ReadS CreateConfig
$creadsPrec :: Int -> ReadS CreateConfig
Prelude.Read, Int -> CreateConfig -> ShowS
[CreateConfig] -> ShowS
CreateConfig -> String
(Int -> CreateConfig -> ShowS)
-> (CreateConfig -> String)
-> ([CreateConfig] -> ShowS)
-> Show CreateConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateConfig] -> ShowS
$cshowList :: [CreateConfig] -> ShowS
show :: CreateConfig -> String
$cshow :: CreateConfig -> String
showsPrec :: Int -> CreateConfig -> ShowS
$cshowsPrec :: Int -> CreateConfig -> ShowS
Prelude.Show, (forall x. CreateConfig -> Rep CreateConfig x)
-> (forall x. Rep CreateConfig x -> CreateConfig)
-> Generic CreateConfig
forall x. Rep CreateConfig x -> CreateConfig
forall x. CreateConfig -> Rep CreateConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateConfig x -> CreateConfig
$cfrom :: forall x. CreateConfig -> Rep CreateConfig x
Prelude.Generic)

-- |
-- Create a value of 'CreateConfig' 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:
--
-- 'tags', 'createConfig_tags' - Tags assigned to a @Config@.
--
-- 'configData', 'createConfig_configData' - Parameters of a @Config@.
--
-- 'name', 'createConfig_name' - Name of a @Config@.
newCreateConfig ::
  -- | 'configData'
  ConfigTypeData ->
  -- | 'name'
  Prelude.Text ->
  CreateConfig
newCreateConfig :: ConfigTypeData -> Text -> CreateConfig
newCreateConfig ConfigTypeData
pConfigData_ Text
pName_ =
  CreateConfig' :: Maybe (HashMap Text Text) -> ConfigTypeData -> Text -> CreateConfig
CreateConfig'
    { $sel:tags:CreateConfig' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:configData:CreateConfig' :: ConfigTypeData
configData = ConfigTypeData
pConfigData_,
      $sel:name:CreateConfig' :: Text
name = Text
pName_
    }

-- | Tags assigned to a @Config@.
createConfig_tags :: Lens.Lens' CreateConfig (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createConfig_tags :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreateConfig -> f CreateConfig
createConfig_tags = (CreateConfig -> Maybe (HashMap Text Text))
-> (CreateConfig -> Maybe (HashMap Text Text) -> CreateConfig)
-> Lens
     CreateConfig
     CreateConfig
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConfig' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateConfig' :: CreateConfig -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreateConfig
s@CreateConfig' {} Maybe (HashMap Text Text)
a -> CreateConfig
s {$sel:tags:CreateConfig' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreateConfig) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> CreateConfig -> f CreateConfig)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreateConfig
-> f CreateConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Parameters of a @Config@.
createConfig_configData :: Lens.Lens' CreateConfig ConfigTypeData
createConfig_configData :: (ConfigTypeData -> f ConfigTypeData)
-> CreateConfig -> f CreateConfig
createConfig_configData = (CreateConfig -> ConfigTypeData)
-> (CreateConfig -> ConfigTypeData -> CreateConfig)
-> Lens CreateConfig CreateConfig ConfigTypeData ConfigTypeData
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConfig' {ConfigTypeData
configData :: ConfigTypeData
$sel:configData:CreateConfig' :: CreateConfig -> ConfigTypeData
configData} -> ConfigTypeData
configData) (\s :: CreateConfig
s@CreateConfig' {} ConfigTypeData
a -> CreateConfig
s {$sel:configData:CreateConfig' :: ConfigTypeData
configData = ConfigTypeData
a} :: CreateConfig)

-- | Name of a @Config@.
createConfig_name :: Lens.Lens' CreateConfig Prelude.Text
createConfig_name :: (Text -> f Text) -> CreateConfig -> f CreateConfig
createConfig_name = (CreateConfig -> Text)
-> (CreateConfig -> Text -> CreateConfig)
-> Lens CreateConfig CreateConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConfig' {Text
name :: Text
$sel:name:CreateConfig' :: CreateConfig -> Text
name} -> Text
name) (\s :: CreateConfig
s@CreateConfig' {} Text
a -> CreateConfig
s {$sel:name:CreateConfig' :: Text
name = Text
a} :: CreateConfig)

instance Core.AWSRequest CreateConfig where
  type AWSResponse CreateConfig = ConfigIdResponse
  request :: CreateConfig -> Request CreateConfig
request = Service -> CreateConfig -> Request CreateConfig
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateConfig
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateConfig)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateConfig))
-> Logger
-> Service
-> Proxy CreateConfig
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateConfig)))
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 -> Object -> Either String ConfigIdResponse
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable CreateConfig

instance Prelude.NFData CreateConfig

instance Core.ToHeaders CreateConfig where
  toHeaders :: CreateConfig -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateConfig -> 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 CreateConfig where
  toJSON :: CreateConfig -> Value
toJSON CreateConfig' {Maybe (HashMap Text Text)
Text
ConfigTypeData
name :: Text
configData :: ConfigTypeData
tags :: Maybe (HashMap Text Text)
$sel:name:CreateConfig' :: CreateConfig -> Text
$sel:configData:CreateConfig' :: CreateConfig -> ConfigTypeData
$sel:tags:CreateConfig' :: CreateConfig -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"tags" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"configData" Text -> ConfigTypeData -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ConfigTypeData
configData),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )

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

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