{-# 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.ElasticSearch.AssociatePackage
-- 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)
--
-- Associates a package with an Amazon ES domain.
module Amazonka.ElasticSearch.AssociatePackage
  ( -- * Creating a Request
    AssociatePackage (..),
    newAssociatePackage,

    -- * Request Lenses
    associatePackage_packageID,
    associatePackage_domainName,

    -- * Destructuring the Response
    AssociatePackageResponse (..),
    newAssociatePackageResponse,

    -- * Response Lenses
    associatePackageResponse_domainPackageDetails,
    associatePackageResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.ElasticSearch.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

-- | Container for request parameters to @ AssociatePackage @ operation.
--
-- /See:/ 'newAssociatePackage' smart constructor.
data AssociatePackage = AssociatePackage'
  { -- | Internal ID of the package that you want to associate with a domain. Use
    -- @DescribePackages@ to find this value.
    AssociatePackage -> Text
packageID :: Prelude.Text,
    -- | Name of the domain that you want to associate the package with.
    AssociatePackage -> Text
domainName :: Prelude.Text
  }
  deriving (AssociatePackage -> AssociatePackage -> Bool
(AssociatePackage -> AssociatePackage -> Bool)
-> (AssociatePackage -> AssociatePackage -> Bool)
-> Eq AssociatePackage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociatePackage -> AssociatePackage -> Bool
$c/= :: AssociatePackage -> AssociatePackage -> Bool
== :: AssociatePackage -> AssociatePackage -> Bool
$c== :: AssociatePackage -> AssociatePackage -> Bool
Prelude.Eq, ReadPrec [AssociatePackage]
ReadPrec AssociatePackage
Int -> ReadS AssociatePackage
ReadS [AssociatePackage]
(Int -> ReadS AssociatePackage)
-> ReadS [AssociatePackage]
-> ReadPrec AssociatePackage
-> ReadPrec [AssociatePackage]
-> Read AssociatePackage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociatePackage]
$creadListPrec :: ReadPrec [AssociatePackage]
readPrec :: ReadPrec AssociatePackage
$creadPrec :: ReadPrec AssociatePackage
readList :: ReadS [AssociatePackage]
$creadList :: ReadS [AssociatePackage]
readsPrec :: Int -> ReadS AssociatePackage
$creadsPrec :: Int -> ReadS AssociatePackage
Prelude.Read, Int -> AssociatePackage -> ShowS
[AssociatePackage] -> ShowS
AssociatePackage -> String
(Int -> AssociatePackage -> ShowS)
-> (AssociatePackage -> String)
-> ([AssociatePackage] -> ShowS)
-> Show AssociatePackage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociatePackage] -> ShowS
$cshowList :: [AssociatePackage] -> ShowS
show :: AssociatePackage -> String
$cshow :: AssociatePackage -> String
showsPrec :: Int -> AssociatePackage -> ShowS
$cshowsPrec :: Int -> AssociatePackage -> ShowS
Prelude.Show, (forall x. AssociatePackage -> Rep AssociatePackage x)
-> (forall x. Rep AssociatePackage x -> AssociatePackage)
-> Generic AssociatePackage
forall x. Rep AssociatePackage x -> AssociatePackage
forall x. AssociatePackage -> Rep AssociatePackage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociatePackage x -> AssociatePackage
$cfrom :: forall x. AssociatePackage -> Rep AssociatePackage x
Prelude.Generic)

-- |
-- Create a value of 'AssociatePackage' 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:
--
-- 'packageID', 'associatePackage_packageID' - Internal ID of the package that you want to associate with a domain. Use
-- @DescribePackages@ to find this value.
--
-- 'domainName', 'associatePackage_domainName' - Name of the domain that you want to associate the package with.
newAssociatePackage ::
  -- | 'packageID'
  Prelude.Text ->
  -- | 'domainName'
  Prelude.Text ->
  AssociatePackage
newAssociatePackage :: Text -> Text -> AssociatePackage
newAssociatePackage Text
pPackageID_ Text
pDomainName_ =
  AssociatePackage' :: Text -> Text -> AssociatePackage
AssociatePackage'
    { $sel:packageID:AssociatePackage' :: Text
packageID = Text
pPackageID_,
      $sel:domainName:AssociatePackage' :: Text
domainName = Text
pDomainName_
    }

-- | Internal ID of the package that you want to associate with a domain. Use
-- @DescribePackages@ to find this value.
associatePackage_packageID :: Lens.Lens' AssociatePackage Prelude.Text
associatePackage_packageID :: (Text -> f Text) -> AssociatePackage -> f AssociatePackage
associatePackage_packageID = (AssociatePackage -> Text)
-> (AssociatePackage -> Text -> AssociatePackage)
-> Lens AssociatePackage AssociatePackage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociatePackage' {Text
packageID :: Text
$sel:packageID:AssociatePackage' :: AssociatePackage -> Text
packageID} -> Text
packageID) (\s :: AssociatePackage
s@AssociatePackage' {} Text
a -> AssociatePackage
s {$sel:packageID:AssociatePackage' :: Text
packageID = Text
a} :: AssociatePackage)

-- | Name of the domain that you want to associate the package with.
associatePackage_domainName :: Lens.Lens' AssociatePackage Prelude.Text
associatePackage_domainName :: (Text -> f Text) -> AssociatePackage -> f AssociatePackage
associatePackage_domainName = (AssociatePackage -> Text)
-> (AssociatePackage -> Text -> AssociatePackage)
-> Lens AssociatePackage AssociatePackage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociatePackage' {Text
domainName :: Text
$sel:domainName:AssociatePackage' :: AssociatePackage -> Text
domainName} -> Text
domainName) (\s :: AssociatePackage
s@AssociatePackage' {} Text
a -> AssociatePackage
s {$sel:domainName:AssociatePackage' :: Text
domainName = Text
a} :: AssociatePackage)

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

instance Prelude.NFData AssociatePackage

instance Core.ToHeaders AssociatePackage where
  toHeaders :: AssociatePackage -> ResponseHeaders
toHeaders = ResponseHeaders -> AssociatePackage -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON AssociatePackage where
  toJSON :: AssociatePackage -> Value
toJSON = Value -> AssociatePackage -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath AssociatePackage where
  toPath :: AssociatePackage -> ByteString
toPath AssociatePackage' {Text
domainName :: Text
packageID :: Text
$sel:domainName:AssociatePackage' :: AssociatePackage -> Text
$sel:packageID:AssociatePackage' :: AssociatePackage -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2015-01-01/packages/associate/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
packageID,
        ByteString
"/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
domainName
      ]

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

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

-- |
-- Create a value of 'AssociatePackageResponse' 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:
--
-- 'domainPackageDetails', 'associatePackageResponse_domainPackageDetails' - @DomainPackageDetails@
--
-- 'httpStatus', 'associatePackageResponse_httpStatus' - The response's http status code.
newAssociatePackageResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AssociatePackageResponse
newAssociatePackageResponse :: Int -> AssociatePackageResponse
newAssociatePackageResponse Int
pHttpStatus_ =
  AssociatePackageResponse' :: Maybe DomainPackageDetails -> Int -> AssociatePackageResponse
AssociatePackageResponse'
    { $sel:domainPackageDetails:AssociatePackageResponse' :: Maybe DomainPackageDetails
domainPackageDetails =
        Maybe DomainPackageDetails
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AssociatePackageResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | @DomainPackageDetails@
associatePackageResponse_domainPackageDetails :: Lens.Lens' AssociatePackageResponse (Prelude.Maybe DomainPackageDetails)
associatePackageResponse_domainPackageDetails :: (Maybe DomainPackageDetails -> f (Maybe DomainPackageDetails))
-> AssociatePackageResponse -> f AssociatePackageResponse
associatePackageResponse_domainPackageDetails = (AssociatePackageResponse -> Maybe DomainPackageDetails)
-> (AssociatePackageResponse
    -> Maybe DomainPackageDetails -> AssociatePackageResponse)
-> Lens
     AssociatePackageResponse
     AssociatePackageResponse
     (Maybe DomainPackageDetails)
     (Maybe DomainPackageDetails)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociatePackageResponse' {Maybe DomainPackageDetails
domainPackageDetails :: Maybe DomainPackageDetails
$sel:domainPackageDetails:AssociatePackageResponse' :: AssociatePackageResponse -> Maybe DomainPackageDetails
domainPackageDetails} -> Maybe DomainPackageDetails
domainPackageDetails) (\s :: AssociatePackageResponse
s@AssociatePackageResponse' {} Maybe DomainPackageDetails
a -> AssociatePackageResponse
s {$sel:domainPackageDetails:AssociatePackageResponse' :: Maybe DomainPackageDetails
domainPackageDetails = Maybe DomainPackageDetails
a} :: AssociatePackageResponse)

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

instance Prelude.NFData AssociatePackageResponse