{-# 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.LicenseManagerUserSubscriptions.AssociateUser
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Associates the user to an EC2 instance to utilize user-based
-- subscriptions.
--
-- Your estimated bill for charges on the number of users and related costs
-- will take 48 hours to appear for billing periods that haven\'t closed
-- (marked as __Pending__ billing status) in Amazon Web Services Billing.
-- For more information, see
-- <https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/invoice.html Viewing your monthly charges>
-- in the /Amazon Web Services Billing User Guide/.
module Amazonka.LicenseManagerUserSubscriptions.AssociateUser
  ( -- * Creating a Request
    AssociateUser (..),
    newAssociateUser,

    -- * Request Lenses
    associateUser_domain,
    associateUser_identityProvider,
    associateUser_instanceId,
    associateUser_username,

    -- * Destructuring the Response
    AssociateUserResponse (..),
    newAssociateUserResponse,

    -- * Response Lenses
    associateUserResponse_httpStatus,
    associateUserResponse_instanceUserSummary,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LicenseManagerUserSubscriptions.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAssociateUser' smart constructor.
data AssociateUser = AssociateUser'
  { -- | The domain name of the user.
    AssociateUser -> Maybe Text
domain :: Prelude.Maybe Prelude.Text,
    -- | The identity provider of the user.
    AssociateUser -> IdentityProvider
identityProvider :: IdentityProvider,
    -- | The ID of the EC2 instance, which provides user-based subscriptions.
    AssociateUser -> Text
instanceId :: Prelude.Text,
    -- | The user name from the identity provider for the user.
    AssociateUser -> Text
username :: Prelude.Text
  }
  deriving (AssociateUser -> AssociateUser -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateUser -> AssociateUser -> Bool
$c/= :: AssociateUser -> AssociateUser -> Bool
== :: AssociateUser -> AssociateUser -> Bool
$c== :: AssociateUser -> AssociateUser -> Bool
Prelude.Eq, ReadPrec [AssociateUser]
ReadPrec AssociateUser
Int -> ReadS AssociateUser
ReadS [AssociateUser]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateUser]
$creadListPrec :: ReadPrec [AssociateUser]
readPrec :: ReadPrec AssociateUser
$creadPrec :: ReadPrec AssociateUser
readList :: ReadS [AssociateUser]
$creadList :: ReadS [AssociateUser]
readsPrec :: Int -> ReadS AssociateUser
$creadsPrec :: Int -> ReadS AssociateUser
Prelude.Read, Int -> AssociateUser -> ShowS
[AssociateUser] -> ShowS
AssociateUser -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateUser] -> ShowS
$cshowList :: [AssociateUser] -> ShowS
show :: AssociateUser -> String
$cshow :: AssociateUser -> String
showsPrec :: Int -> AssociateUser -> ShowS
$cshowsPrec :: Int -> AssociateUser -> ShowS
Prelude.Show, forall x. Rep AssociateUser x -> AssociateUser
forall x. AssociateUser -> Rep AssociateUser x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateUser x -> AssociateUser
$cfrom :: forall x. AssociateUser -> Rep AssociateUser x
Prelude.Generic)

-- |
-- Create a value of 'AssociateUser' 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:
--
-- 'domain', 'associateUser_domain' - The domain name of the user.
--
-- 'identityProvider', 'associateUser_identityProvider' - The identity provider of the user.
--
-- 'instanceId', 'associateUser_instanceId' - The ID of the EC2 instance, which provides user-based subscriptions.
--
-- 'username', 'associateUser_username' - The user name from the identity provider for the user.
newAssociateUser ::
  -- | 'identityProvider'
  IdentityProvider ->
  -- | 'instanceId'
  Prelude.Text ->
  -- | 'username'
  Prelude.Text ->
  AssociateUser
newAssociateUser :: IdentityProvider -> Text -> Text -> AssociateUser
newAssociateUser
  IdentityProvider
pIdentityProvider_
  Text
pInstanceId_
  Text
pUsername_ =
    AssociateUser'
      { $sel:domain:AssociateUser' :: Maybe Text
domain = forall a. Maybe a
Prelude.Nothing,
        $sel:identityProvider:AssociateUser' :: IdentityProvider
identityProvider = IdentityProvider
pIdentityProvider_,
        $sel:instanceId:AssociateUser' :: Text
instanceId = Text
pInstanceId_,
        $sel:username:AssociateUser' :: Text
username = Text
pUsername_
      }

-- | The domain name of the user.
associateUser_domain :: Lens.Lens' AssociateUser (Prelude.Maybe Prelude.Text)
associateUser_domain :: Lens' AssociateUser (Maybe Text)
associateUser_domain = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateUser' {Maybe Text
domain :: Maybe Text
$sel:domain:AssociateUser' :: AssociateUser -> Maybe Text
domain} -> Maybe Text
domain) (\s :: AssociateUser
s@AssociateUser' {} Maybe Text
a -> AssociateUser
s {$sel:domain:AssociateUser' :: Maybe Text
domain = Maybe Text
a} :: AssociateUser)

-- | The identity provider of the user.
associateUser_identityProvider :: Lens.Lens' AssociateUser IdentityProvider
associateUser_identityProvider :: Lens' AssociateUser IdentityProvider
associateUser_identityProvider = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateUser' {IdentityProvider
identityProvider :: IdentityProvider
$sel:identityProvider:AssociateUser' :: AssociateUser -> IdentityProvider
identityProvider} -> IdentityProvider
identityProvider) (\s :: AssociateUser
s@AssociateUser' {} IdentityProvider
a -> AssociateUser
s {$sel:identityProvider:AssociateUser' :: IdentityProvider
identityProvider = IdentityProvider
a} :: AssociateUser)

-- | The ID of the EC2 instance, which provides user-based subscriptions.
associateUser_instanceId :: Lens.Lens' AssociateUser Prelude.Text
associateUser_instanceId :: Lens' AssociateUser Text
associateUser_instanceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateUser' {Text
instanceId :: Text
$sel:instanceId:AssociateUser' :: AssociateUser -> Text
instanceId} -> Text
instanceId) (\s :: AssociateUser
s@AssociateUser' {} Text
a -> AssociateUser
s {$sel:instanceId:AssociateUser' :: Text
instanceId = Text
a} :: AssociateUser)

-- | The user name from the identity provider for the user.
associateUser_username :: Lens.Lens' AssociateUser Prelude.Text
associateUser_username :: Lens' AssociateUser Text
associateUser_username = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateUser' {Text
username :: Text
$sel:username:AssociateUser' :: AssociateUser -> Text
username} -> Text
username) (\s :: AssociateUser
s@AssociateUser' {} Text
a -> AssociateUser
s {$sel:username:AssociateUser' :: Text
username = Text
a} :: AssociateUser)

instance Core.AWSRequest AssociateUser where
  type
    AWSResponse AssociateUser =
      AssociateUserResponse
  request :: (Service -> Service) -> AssociateUser -> Request AssociateUser
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 AssociateUser
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssociateUser)))
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 ->
          Int -> InstanceUserSummary -> AssociateUserResponse
AssociateUserResponse'
            forall (f :: * -> *) a b. Functor 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))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"InstanceUserSummary")
      )

instance Prelude.Hashable AssociateUser where
  hashWithSalt :: Int -> AssociateUser -> Int
hashWithSalt Int
_salt AssociateUser' {Maybe Text
Text
IdentityProvider
username :: Text
instanceId :: Text
identityProvider :: IdentityProvider
domain :: Maybe Text
$sel:username:AssociateUser' :: AssociateUser -> Text
$sel:instanceId:AssociateUser' :: AssociateUser -> Text
$sel:identityProvider:AssociateUser' :: AssociateUser -> IdentityProvider
$sel:domain:AssociateUser' :: AssociateUser -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
domain
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` IdentityProvider
identityProvider
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
instanceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
username

instance Prelude.NFData AssociateUser where
  rnf :: AssociateUser -> ()
rnf AssociateUser' {Maybe Text
Text
IdentityProvider
username :: Text
instanceId :: Text
identityProvider :: IdentityProvider
domain :: Maybe Text
$sel:username:AssociateUser' :: AssociateUser -> Text
$sel:instanceId:AssociateUser' :: AssociateUser -> Text
$sel:identityProvider:AssociateUser' :: AssociateUser -> IdentityProvider
$sel:domain:AssociateUser' :: AssociateUser -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
domain
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf IdentityProvider
identityProvider
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
instanceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
username

instance Data.ToHeaders AssociateUser where
  toHeaders :: AssociateUser -> 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 AssociateUser where
  toJSON :: AssociateUser -> Value
toJSON AssociateUser' {Maybe Text
Text
IdentityProvider
username :: Text
instanceId :: Text
identityProvider :: IdentityProvider
domain :: Maybe Text
$sel:username:AssociateUser' :: AssociateUser -> Text
$sel:instanceId:AssociateUser' :: AssociateUser -> Text
$sel:identityProvider:AssociateUser' :: AssociateUser -> IdentityProvider
$sel:domain:AssociateUser' :: AssociateUser -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Domain" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
domain,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"IdentityProvider" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= IdentityProvider
identityProvider),
            forall a. a -> Maybe a
Prelude.Just (Key
"InstanceId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
instanceId),
            forall a. a -> Maybe a
Prelude.Just (Key
"Username" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
username)
          ]
      )

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

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

-- | /See:/ 'newAssociateUserResponse' smart constructor.
data AssociateUserResponse = AssociateUserResponse'
  { -- | The response's http status code.
    AssociateUserResponse -> Int
httpStatus :: Prelude.Int,
    -- | Metadata that describes the associate user operation.
    AssociateUserResponse -> InstanceUserSummary
instanceUserSummary :: InstanceUserSummary
  }
  deriving (AssociateUserResponse -> AssociateUserResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateUserResponse -> AssociateUserResponse -> Bool
$c/= :: AssociateUserResponse -> AssociateUserResponse -> Bool
== :: AssociateUserResponse -> AssociateUserResponse -> Bool
$c== :: AssociateUserResponse -> AssociateUserResponse -> Bool
Prelude.Eq, ReadPrec [AssociateUserResponse]
ReadPrec AssociateUserResponse
Int -> ReadS AssociateUserResponse
ReadS [AssociateUserResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateUserResponse]
$creadListPrec :: ReadPrec [AssociateUserResponse]
readPrec :: ReadPrec AssociateUserResponse
$creadPrec :: ReadPrec AssociateUserResponse
readList :: ReadS [AssociateUserResponse]
$creadList :: ReadS [AssociateUserResponse]
readsPrec :: Int -> ReadS AssociateUserResponse
$creadsPrec :: Int -> ReadS AssociateUserResponse
Prelude.Read, Int -> AssociateUserResponse -> ShowS
[AssociateUserResponse] -> ShowS
AssociateUserResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateUserResponse] -> ShowS
$cshowList :: [AssociateUserResponse] -> ShowS
show :: AssociateUserResponse -> String
$cshow :: AssociateUserResponse -> String
showsPrec :: Int -> AssociateUserResponse -> ShowS
$cshowsPrec :: Int -> AssociateUserResponse -> ShowS
Prelude.Show, forall x. Rep AssociateUserResponse x -> AssociateUserResponse
forall x. AssociateUserResponse -> Rep AssociateUserResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateUserResponse x -> AssociateUserResponse
$cfrom :: forall x. AssociateUserResponse -> Rep AssociateUserResponse x
Prelude.Generic)

-- |
-- Create a value of 'AssociateUserResponse' 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:
--
-- 'httpStatus', 'associateUserResponse_httpStatus' - The response's http status code.
--
-- 'instanceUserSummary', 'associateUserResponse_instanceUserSummary' - Metadata that describes the associate user operation.
newAssociateUserResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'instanceUserSummary'
  InstanceUserSummary ->
  AssociateUserResponse
newAssociateUserResponse :: Int -> InstanceUserSummary -> AssociateUserResponse
newAssociateUserResponse
  Int
pHttpStatus_
  InstanceUserSummary
pInstanceUserSummary_ =
    AssociateUserResponse'
      { $sel:httpStatus:AssociateUserResponse' :: Int
httpStatus = Int
pHttpStatus_,
        $sel:instanceUserSummary:AssociateUserResponse' :: InstanceUserSummary
instanceUserSummary = InstanceUserSummary
pInstanceUserSummary_
      }

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

-- | Metadata that describes the associate user operation.
associateUserResponse_instanceUserSummary :: Lens.Lens' AssociateUserResponse InstanceUserSummary
associateUserResponse_instanceUserSummary :: Lens' AssociateUserResponse InstanceUserSummary
associateUserResponse_instanceUserSummary = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateUserResponse' {InstanceUserSummary
instanceUserSummary :: InstanceUserSummary
$sel:instanceUserSummary:AssociateUserResponse' :: AssociateUserResponse -> InstanceUserSummary
instanceUserSummary} -> InstanceUserSummary
instanceUserSummary) (\s :: AssociateUserResponse
s@AssociateUserResponse' {} InstanceUserSummary
a -> AssociateUserResponse
s {$sel:instanceUserSummary:AssociateUserResponse' :: InstanceUserSummary
instanceUserSummary = InstanceUserSummary
a} :: AssociateUserResponse)

instance Prelude.NFData AssociateUserResponse where
  rnf :: AssociateUserResponse -> ()
rnf AssociateUserResponse' {Int
InstanceUserSummary
instanceUserSummary :: InstanceUserSummary
httpStatus :: Int
$sel:instanceUserSummary:AssociateUserResponse' :: AssociateUserResponse -> InstanceUserSummary
$sel:httpStatus:AssociateUserResponse' :: AssociateUserResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf InstanceUserSummary
instanceUserSummary