{-# 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.CognitoIdentityProvider.StartUserImportJob
-- 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)
--
-- Starts the user import.
module Amazonka.CognitoIdentityProvider.StartUserImportJob
  ( -- * Creating a Request
    StartUserImportJob (..),
    newStartUserImportJob,

    -- * Request Lenses
    startUserImportJob_userPoolId,
    startUserImportJob_jobId,

    -- * Destructuring the Response
    StartUserImportJobResponse (..),
    newStartUserImportJobResponse,

    -- * Response Lenses
    startUserImportJobResponse_userImportJob,
    startUserImportJobResponse_httpStatus,
  )
where

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

-- | Represents the request to start the user import job.
--
-- /See:/ 'newStartUserImportJob' smart constructor.
data StartUserImportJob = StartUserImportJob'
  { -- | The user pool ID for the user pool that the users are being imported
    -- into.
    StartUserImportJob -> Text
userPoolId :: Prelude.Text,
    -- | The job ID for the user import job.
    StartUserImportJob -> Text
jobId :: Prelude.Text
  }
  deriving (StartUserImportJob -> StartUserImportJob -> Bool
(StartUserImportJob -> StartUserImportJob -> Bool)
-> (StartUserImportJob -> StartUserImportJob -> Bool)
-> Eq StartUserImportJob
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartUserImportJob -> StartUserImportJob -> Bool
$c/= :: StartUserImportJob -> StartUserImportJob -> Bool
== :: StartUserImportJob -> StartUserImportJob -> Bool
$c== :: StartUserImportJob -> StartUserImportJob -> Bool
Prelude.Eq, ReadPrec [StartUserImportJob]
ReadPrec StartUserImportJob
Int -> ReadS StartUserImportJob
ReadS [StartUserImportJob]
(Int -> ReadS StartUserImportJob)
-> ReadS [StartUserImportJob]
-> ReadPrec StartUserImportJob
-> ReadPrec [StartUserImportJob]
-> Read StartUserImportJob
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartUserImportJob]
$creadListPrec :: ReadPrec [StartUserImportJob]
readPrec :: ReadPrec StartUserImportJob
$creadPrec :: ReadPrec StartUserImportJob
readList :: ReadS [StartUserImportJob]
$creadList :: ReadS [StartUserImportJob]
readsPrec :: Int -> ReadS StartUserImportJob
$creadsPrec :: Int -> ReadS StartUserImportJob
Prelude.Read, Int -> StartUserImportJob -> ShowS
[StartUserImportJob] -> ShowS
StartUserImportJob -> String
(Int -> StartUserImportJob -> ShowS)
-> (StartUserImportJob -> String)
-> ([StartUserImportJob] -> ShowS)
-> Show StartUserImportJob
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartUserImportJob] -> ShowS
$cshowList :: [StartUserImportJob] -> ShowS
show :: StartUserImportJob -> String
$cshow :: StartUserImportJob -> String
showsPrec :: Int -> StartUserImportJob -> ShowS
$cshowsPrec :: Int -> StartUserImportJob -> ShowS
Prelude.Show, (forall x. StartUserImportJob -> Rep StartUserImportJob x)
-> (forall x. Rep StartUserImportJob x -> StartUserImportJob)
-> Generic StartUserImportJob
forall x. Rep StartUserImportJob x -> StartUserImportJob
forall x. StartUserImportJob -> Rep StartUserImportJob x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartUserImportJob x -> StartUserImportJob
$cfrom :: forall x. StartUserImportJob -> Rep StartUserImportJob x
Prelude.Generic)

-- |
-- Create a value of 'StartUserImportJob' 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:
--
-- 'userPoolId', 'startUserImportJob_userPoolId' - The user pool ID for the user pool that the users are being imported
-- into.
--
-- 'jobId', 'startUserImportJob_jobId' - The job ID for the user import job.
newStartUserImportJob ::
  -- | 'userPoolId'
  Prelude.Text ->
  -- | 'jobId'
  Prelude.Text ->
  StartUserImportJob
newStartUserImportJob :: Text -> Text -> StartUserImportJob
newStartUserImportJob Text
pUserPoolId_ Text
pJobId_ =
  StartUserImportJob' :: Text -> Text -> StartUserImportJob
StartUserImportJob'
    { $sel:userPoolId:StartUserImportJob' :: Text
userPoolId = Text
pUserPoolId_,
      $sel:jobId:StartUserImportJob' :: Text
jobId = Text
pJobId_
    }

-- | The user pool ID for the user pool that the users are being imported
-- into.
startUserImportJob_userPoolId :: Lens.Lens' StartUserImportJob Prelude.Text
startUserImportJob_userPoolId :: (Text -> f Text) -> StartUserImportJob -> f StartUserImportJob
startUserImportJob_userPoolId = (StartUserImportJob -> Text)
-> (StartUserImportJob -> Text -> StartUserImportJob)
-> Lens StartUserImportJob StartUserImportJob Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartUserImportJob' {Text
userPoolId :: Text
$sel:userPoolId:StartUserImportJob' :: StartUserImportJob -> Text
userPoolId} -> Text
userPoolId) (\s :: StartUserImportJob
s@StartUserImportJob' {} Text
a -> StartUserImportJob
s {$sel:userPoolId:StartUserImportJob' :: Text
userPoolId = Text
a} :: StartUserImportJob)

-- | The job ID for the user import job.
startUserImportJob_jobId :: Lens.Lens' StartUserImportJob Prelude.Text
startUserImportJob_jobId :: (Text -> f Text) -> StartUserImportJob -> f StartUserImportJob
startUserImportJob_jobId = (StartUserImportJob -> Text)
-> (StartUserImportJob -> Text -> StartUserImportJob)
-> Lens StartUserImportJob StartUserImportJob Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartUserImportJob' {Text
jobId :: Text
$sel:jobId:StartUserImportJob' :: StartUserImportJob -> Text
jobId} -> Text
jobId) (\s :: StartUserImportJob
s@StartUserImportJob' {} Text
a -> StartUserImportJob
s {$sel:jobId:StartUserImportJob' :: Text
jobId = Text
a} :: StartUserImportJob)

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

instance Prelude.NFData StartUserImportJob

instance Core.ToHeaders StartUserImportJob where
  toHeaders :: StartUserImportJob -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartUserImportJob -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSCognitoIdentityProviderService.StartUserImportJob" ::
                          Prelude.ByteString
                      ),
            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 StartUserImportJob where
  toJSON :: StartUserImportJob -> Value
toJSON StartUserImportJob' {Text
jobId :: Text
userPoolId :: Text
$sel:jobId:StartUserImportJob' :: StartUserImportJob -> Text
$sel:userPoolId:StartUserImportJob' :: StartUserImportJob -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"UserPoolId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
userPoolId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"JobId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
jobId)
          ]
      )

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

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

-- | Represents the response from the server to the request to start the user
-- import job.
--
-- /See:/ 'newStartUserImportJobResponse' smart constructor.
data StartUserImportJobResponse = StartUserImportJobResponse'
  { -- | The job object that represents the user import job.
    StartUserImportJobResponse -> Maybe UserImportJobType
userImportJob :: Prelude.Maybe UserImportJobType,
    -- | The response's http status code.
    StartUserImportJobResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartUserImportJobResponse -> StartUserImportJobResponse -> Bool
(StartUserImportJobResponse -> StartUserImportJobResponse -> Bool)
-> (StartUserImportJobResponse
    -> StartUserImportJobResponse -> Bool)
-> Eq StartUserImportJobResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartUserImportJobResponse -> StartUserImportJobResponse -> Bool
$c/= :: StartUserImportJobResponse -> StartUserImportJobResponse -> Bool
== :: StartUserImportJobResponse -> StartUserImportJobResponse -> Bool
$c== :: StartUserImportJobResponse -> StartUserImportJobResponse -> Bool
Prelude.Eq, ReadPrec [StartUserImportJobResponse]
ReadPrec StartUserImportJobResponse
Int -> ReadS StartUserImportJobResponse
ReadS [StartUserImportJobResponse]
(Int -> ReadS StartUserImportJobResponse)
-> ReadS [StartUserImportJobResponse]
-> ReadPrec StartUserImportJobResponse
-> ReadPrec [StartUserImportJobResponse]
-> Read StartUserImportJobResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartUserImportJobResponse]
$creadListPrec :: ReadPrec [StartUserImportJobResponse]
readPrec :: ReadPrec StartUserImportJobResponse
$creadPrec :: ReadPrec StartUserImportJobResponse
readList :: ReadS [StartUserImportJobResponse]
$creadList :: ReadS [StartUserImportJobResponse]
readsPrec :: Int -> ReadS StartUserImportJobResponse
$creadsPrec :: Int -> ReadS StartUserImportJobResponse
Prelude.Read, Int -> StartUserImportJobResponse -> ShowS
[StartUserImportJobResponse] -> ShowS
StartUserImportJobResponse -> String
(Int -> StartUserImportJobResponse -> ShowS)
-> (StartUserImportJobResponse -> String)
-> ([StartUserImportJobResponse] -> ShowS)
-> Show StartUserImportJobResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartUserImportJobResponse] -> ShowS
$cshowList :: [StartUserImportJobResponse] -> ShowS
show :: StartUserImportJobResponse -> String
$cshow :: StartUserImportJobResponse -> String
showsPrec :: Int -> StartUserImportJobResponse -> ShowS
$cshowsPrec :: Int -> StartUserImportJobResponse -> ShowS
Prelude.Show, (forall x.
 StartUserImportJobResponse -> Rep StartUserImportJobResponse x)
-> (forall x.
    Rep StartUserImportJobResponse x -> StartUserImportJobResponse)
-> Generic StartUserImportJobResponse
forall x.
Rep StartUserImportJobResponse x -> StartUserImportJobResponse
forall x.
StartUserImportJobResponse -> Rep StartUserImportJobResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StartUserImportJobResponse x -> StartUserImportJobResponse
$cfrom :: forall x.
StartUserImportJobResponse -> Rep StartUserImportJobResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartUserImportJobResponse' 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:
--
-- 'userImportJob', 'startUserImportJobResponse_userImportJob' - The job object that represents the user import job.
--
-- 'httpStatus', 'startUserImportJobResponse_httpStatus' - The response's http status code.
newStartUserImportJobResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartUserImportJobResponse
newStartUserImportJobResponse :: Int -> StartUserImportJobResponse
newStartUserImportJobResponse Int
pHttpStatus_ =
  StartUserImportJobResponse' :: Maybe UserImportJobType -> Int -> StartUserImportJobResponse
StartUserImportJobResponse'
    { $sel:userImportJob:StartUserImportJobResponse' :: Maybe UserImportJobType
userImportJob =
        Maybe UserImportJobType
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartUserImportJobResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The job object that represents the user import job.
startUserImportJobResponse_userImportJob :: Lens.Lens' StartUserImportJobResponse (Prelude.Maybe UserImportJobType)
startUserImportJobResponse_userImportJob :: (Maybe UserImportJobType -> f (Maybe UserImportJobType))
-> StartUserImportJobResponse -> f StartUserImportJobResponse
startUserImportJobResponse_userImportJob = (StartUserImportJobResponse -> Maybe UserImportJobType)
-> (StartUserImportJobResponse
    -> Maybe UserImportJobType -> StartUserImportJobResponse)
-> Lens
     StartUserImportJobResponse
     StartUserImportJobResponse
     (Maybe UserImportJobType)
     (Maybe UserImportJobType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartUserImportJobResponse' {Maybe UserImportJobType
userImportJob :: Maybe UserImportJobType
$sel:userImportJob:StartUserImportJobResponse' :: StartUserImportJobResponse -> Maybe UserImportJobType
userImportJob} -> Maybe UserImportJobType
userImportJob) (\s :: StartUserImportJobResponse
s@StartUserImportJobResponse' {} Maybe UserImportJobType
a -> StartUserImportJobResponse
s {$sel:userImportJob:StartUserImportJobResponse' :: Maybe UserImportJobType
userImportJob = Maybe UserImportJobType
a} :: StartUserImportJobResponse)

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

instance Prelude.NFData StartUserImportJobResponse