{-# 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.AppSync.AssociateApi
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Maps an endpoint to your custom domain.
module Amazonka.AppSync.AssociateApi
  ( -- * Creating a Request
    AssociateApi (..),
    newAssociateApi,

    -- * Request Lenses
    associateApi_domainName,
    associateApi_apiId,

    -- * Destructuring the Response
    AssociateApiResponse (..),
    newAssociateApiResponse,

    -- * Response Lenses
    associateApiResponse_apiAssociation,
    associateApiResponse_httpStatus,
  )
where

import Amazonka.AppSync.Types
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

-- | /See:/ 'newAssociateApi' smart constructor.
data AssociateApi = AssociateApi'
  { -- | The domain name.
    AssociateApi -> Text
domainName :: Prelude.Text,
    -- | The API ID.
    AssociateApi -> Text
apiId :: Prelude.Text
  }
  deriving (AssociateApi -> AssociateApi -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateApi -> AssociateApi -> Bool
$c/= :: AssociateApi -> AssociateApi -> Bool
== :: AssociateApi -> AssociateApi -> Bool
$c== :: AssociateApi -> AssociateApi -> Bool
Prelude.Eq, ReadPrec [AssociateApi]
ReadPrec AssociateApi
Int -> ReadS AssociateApi
ReadS [AssociateApi]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateApi]
$creadListPrec :: ReadPrec [AssociateApi]
readPrec :: ReadPrec AssociateApi
$creadPrec :: ReadPrec AssociateApi
readList :: ReadS [AssociateApi]
$creadList :: ReadS [AssociateApi]
readsPrec :: Int -> ReadS AssociateApi
$creadsPrec :: Int -> ReadS AssociateApi
Prelude.Read, Int -> AssociateApi -> ShowS
[AssociateApi] -> ShowS
AssociateApi -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateApi] -> ShowS
$cshowList :: [AssociateApi] -> ShowS
show :: AssociateApi -> String
$cshow :: AssociateApi -> String
showsPrec :: Int -> AssociateApi -> ShowS
$cshowsPrec :: Int -> AssociateApi -> ShowS
Prelude.Show, forall x. Rep AssociateApi x -> AssociateApi
forall x. AssociateApi -> Rep AssociateApi x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateApi x -> AssociateApi
$cfrom :: forall x. AssociateApi -> Rep AssociateApi x
Prelude.Generic)

-- |
-- Create a value of 'AssociateApi' 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:
--
-- 'domainName', 'associateApi_domainName' - The domain name.
--
-- 'apiId', 'associateApi_apiId' - The API ID.
newAssociateApi ::
  -- | 'domainName'
  Prelude.Text ->
  -- | 'apiId'
  Prelude.Text ->
  AssociateApi
newAssociateApi :: Text -> Text -> AssociateApi
newAssociateApi Text
pDomainName_ Text
pApiId_ =
  AssociateApi'
    { $sel:domainName:AssociateApi' :: Text
domainName = Text
pDomainName_,
      $sel:apiId:AssociateApi' :: Text
apiId = Text
pApiId_
    }

-- | The domain name.
associateApi_domainName :: Lens.Lens' AssociateApi Prelude.Text
associateApi_domainName :: Lens' AssociateApi Text
associateApi_domainName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateApi' {Text
domainName :: Text
$sel:domainName:AssociateApi' :: AssociateApi -> Text
domainName} -> Text
domainName) (\s :: AssociateApi
s@AssociateApi' {} Text
a -> AssociateApi
s {$sel:domainName:AssociateApi' :: Text
domainName = Text
a} :: AssociateApi)

-- | The API ID.
associateApi_apiId :: Lens.Lens' AssociateApi Prelude.Text
associateApi_apiId :: Lens' AssociateApi Text
associateApi_apiId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateApi' {Text
apiId :: Text
$sel:apiId:AssociateApi' :: AssociateApi -> Text
apiId} -> Text
apiId) (\s :: AssociateApi
s@AssociateApi' {} Text
a -> AssociateApi
s {$sel:apiId:AssociateApi' :: Text
apiId = Text
a} :: AssociateApi)

instance Core.AWSRequest AssociateApi where
  type AWSResponse AssociateApi = AssociateApiResponse
  request :: (Service -> Service) -> AssociateApi -> Request AssociateApi
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 AssociateApi
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssociateApi)))
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 ApiAssociation -> Int -> AssociateApiResponse
AssociateApiResponse'
            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
"apiAssociation")
            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 AssociateApi where
  hashWithSalt :: Int -> AssociateApi -> Int
hashWithSalt Int
_salt AssociateApi' {Text
apiId :: Text
domainName :: Text
$sel:apiId:AssociateApi' :: AssociateApi -> Text
$sel:domainName:AssociateApi' :: AssociateApi -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
domainName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
apiId

instance Prelude.NFData AssociateApi where
  rnf :: AssociateApi -> ()
rnf AssociateApi' {Text
apiId :: Text
domainName :: Text
$sel:apiId:AssociateApi' :: AssociateApi -> Text
$sel:domainName:AssociateApi' :: AssociateApi -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
domainName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
apiId

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

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

instance Data.ToPath AssociateApi where
  toPath :: AssociateApi -> ByteString
toPath AssociateApi' {Text
apiId :: Text
domainName :: Text
$sel:apiId:AssociateApi' :: AssociateApi -> Text
$sel:domainName:AssociateApi' :: AssociateApi -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/v1/domainnames/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
domainName,
        ByteString
"/apiassociation"
      ]

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

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

-- |
-- Create a value of 'AssociateApiResponse' 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:
--
-- 'apiAssociation', 'associateApiResponse_apiAssociation' - The @ApiAssociation@ object.
--
-- 'httpStatus', 'associateApiResponse_httpStatus' - The response's http status code.
newAssociateApiResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AssociateApiResponse
newAssociateApiResponse :: Int -> AssociateApiResponse
newAssociateApiResponse Int
pHttpStatus_ =
  AssociateApiResponse'
    { $sel:apiAssociation:AssociateApiResponse' :: Maybe ApiAssociation
apiAssociation =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AssociateApiResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @ApiAssociation@ object.
associateApiResponse_apiAssociation :: Lens.Lens' AssociateApiResponse (Prelude.Maybe ApiAssociation)
associateApiResponse_apiAssociation :: Lens' AssociateApiResponse (Maybe ApiAssociation)
associateApiResponse_apiAssociation = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateApiResponse' {Maybe ApiAssociation
apiAssociation :: Maybe ApiAssociation
$sel:apiAssociation:AssociateApiResponse' :: AssociateApiResponse -> Maybe ApiAssociation
apiAssociation} -> Maybe ApiAssociation
apiAssociation) (\s :: AssociateApiResponse
s@AssociateApiResponse' {} Maybe ApiAssociation
a -> AssociateApiResponse
s {$sel:apiAssociation:AssociateApiResponse' :: Maybe ApiAssociation
apiAssociation = Maybe ApiAssociation
a} :: AssociateApiResponse)

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

instance Prelude.NFData AssociateApiResponse where
  rnf :: AssociateApiResponse -> ()
rnf AssociateApiResponse' {Int
Maybe ApiAssociation
httpStatus :: Int
apiAssociation :: Maybe ApiAssociation
$sel:httpStatus:AssociateApiResponse' :: AssociateApiResponse -> Int
$sel:apiAssociation:AssociateApiResponse' :: AssociateApiResponse -> Maybe ApiAssociation
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ApiAssociation
apiAssociation
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus