{-# 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.GetCSVHeader
-- 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)
--
-- Gets the header information for the .csv file to be used as input for
-- the user import job.
module Amazonka.CognitoIdentityProvider.GetCSVHeader
  ( -- * Creating a Request
    GetCSVHeader (..),
    newGetCSVHeader,

    -- * Request Lenses
    getCSVHeader_userPoolId,

    -- * Destructuring the Response
    GetCSVHeaderResponse (..),
    newGetCSVHeaderResponse,

    -- * Response Lenses
    getCSVHeaderResponse_userPoolId,
    getCSVHeaderResponse_cSVHeader,
    getCSVHeaderResponse_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 get the header information for the .csv file
-- for the user import job.
--
-- /See:/ 'newGetCSVHeader' smart constructor.
data GetCSVHeader = GetCSVHeader'
  { -- | The user pool ID for the user pool that the users are to be imported
    -- into.
    GetCSVHeader -> Text
userPoolId :: Prelude.Text
  }
  deriving (GetCSVHeader -> GetCSVHeader -> Bool
(GetCSVHeader -> GetCSVHeader -> Bool)
-> (GetCSVHeader -> GetCSVHeader -> Bool) -> Eq GetCSVHeader
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCSVHeader -> GetCSVHeader -> Bool
$c/= :: GetCSVHeader -> GetCSVHeader -> Bool
== :: GetCSVHeader -> GetCSVHeader -> Bool
$c== :: GetCSVHeader -> GetCSVHeader -> Bool
Prelude.Eq, ReadPrec [GetCSVHeader]
ReadPrec GetCSVHeader
Int -> ReadS GetCSVHeader
ReadS [GetCSVHeader]
(Int -> ReadS GetCSVHeader)
-> ReadS [GetCSVHeader]
-> ReadPrec GetCSVHeader
-> ReadPrec [GetCSVHeader]
-> Read GetCSVHeader
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCSVHeader]
$creadListPrec :: ReadPrec [GetCSVHeader]
readPrec :: ReadPrec GetCSVHeader
$creadPrec :: ReadPrec GetCSVHeader
readList :: ReadS [GetCSVHeader]
$creadList :: ReadS [GetCSVHeader]
readsPrec :: Int -> ReadS GetCSVHeader
$creadsPrec :: Int -> ReadS GetCSVHeader
Prelude.Read, Int -> GetCSVHeader -> ShowS
[GetCSVHeader] -> ShowS
GetCSVHeader -> String
(Int -> GetCSVHeader -> ShowS)
-> (GetCSVHeader -> String)
-> ([GetCSVHeader] -> ShowS)
-> Show GetCSVHeader
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCSVHeader] -> ShowS
$cshowList :: [GetCSVHeader] -> ShowS
show :: GetCSVHeader -> String
$cshow :: GetCSVHeader -> String
showsPrec :: Int -> GetCSVHeader -> ShowS
$cshowsPrec :: Int -> GetCSVHeader -> ShowS
Prelude.Show, (forall x. GetCSVHeader -> Rep GetCSVHeader x)
-> (forall x. Rep GetCSVHeader x -> GetCSVHeader)
-> Generic GetCSVHeader
forall x. Rep GetCSVHeader x -> GetCSVHeader
forall x. GetCSVHeader -> Rep GetCSVHeader x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCSVHeader x -> GetCSVHeader
$cfrom :: forall x. GetCSVHeader -> Rep GetCSVHeader x
Prelude.Generic)

-- |
-- Create a value of 'GetCSVHeader' 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', 'getCSVHeader_userPoolId' - The user pool ID for the user pool that the users are to be imported
-- into.
newGetCSVHeader ::
  -- | 'userPoolId'
  Prelude.Text ->
  GetCSVHeader
newGetCSVHeader :: Text -> GetCSVHeader
newGetCSVHeader Text
pUserPoolId_ =
  GetCSVHeader' :: Text -> GetCSVHeader
GetCSVHeader' {$sel:userPoolId:GetCSVHeader' :: Text
userPoolId = Text
pUserPoolId_}

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

instance Core.AWSRequest GetCSVHeader where
  type AWSResponse GetCSVHeader = GetCSVHeaderResponse
  request :: GetCSVHeader -> Request GetCSVHeader
request = Service -> GetCSVHeader -> Request GetCSVHeader
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetCSVHeader
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetCSVHeader)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetCSVHeader))
-> Logger
-> Service
-> Proxy GetCSVHeader
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetCSVHeader)))
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 Text -> Maybe [Text] -> Int -> GetCSVHeaderResponse
GetCSVHeaderResponse'
            (Maybe Text -> Maybe [Text] -> Int -> GetCSVHeaderResponse)
-> Either String (Maybe Text)
-> Either String (Maybe [Text] -> Int -> GetCSVHeaderResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"UserPoolId")
            Either String (Maybe [Text] -> Int -> GetCSVHeaderResponse)
-> Either String (Maybe [Text])
-> Either String (Int -> GetCSVHeaderResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"CSVHeader" Either String (Maybe (Maybe [Text]))
-> Maybe [Text] -> Either String (Maybe [Text])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> GetCSVHeaderResponse)
-> Either String Int -> Either String GetCSVHeaderResponse
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 GetCSVHeader

instance Prelude.NFData GetCSVHeader

instance Core.ToHeaders GetCSVHeader where
  toHeaders :: GetCSVHeader -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetCSVHeader -> 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.GetCSVHeader" ::
                          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 GetCSVHeader where
  toJSON :: GetCSVHeader -> Value
toJSON GetCSVHeader' {Text
userPoolId :: Text
$sel:userPoolId:GetCSVHeader' :: GetCSVHeader -> 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)]
      )

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

instance Core.ToQuery GetCSVHeader where
  toQuery :: GetCSVHeader -> QueryString
toQuery = QueryString -> GetCSVHeader -> 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 get the header
-- information for the .csv file for the user import job.
--
-- /See:/ 'newGetCSVHeaderResponse' smart constructor.
data GetCSVHeaderResponse = GetCSVHeaderResponse'
  { -- | The user pool ID for the user pool that the users are to be imported
    -- into.
    GetCSVHeaderResponse -> Maybe Text
userPoolId :: Prelude.Maybe Prelude.Text,
    -- | The header information for the .csv file for the user import job.
    GetCSVHeaderResponse -> Maybe [Text]
cSVHeader :: Prelude.Maybe [Prelude.Text],
    -- | The response's http status code.
    GetCSVHeaderResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetCSVHeaderResponse -> GetCSVHeaderResponse -> Bool
(GetCSVHeaderResponse -> GetCSVHeaderResponse -> Bool)
-> (GetCSVHeaderResponse -> GetCSVHeaderResponse -> Bool)
-> Eq GetCSVHeaderResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCSVHeaderResponse -> GetCSVHeaderResponse -> Bool
$c/= :: GetCSVHeaderResponse -> GetCSVHeaderResponse -> Bool
== :: GetCSVHeaderResponse -> GetCSVHeaderResponse -> Bool
$c== :: GetCSVHeaderResponse -> GetCSVHeaderResponse -> Bool
Prelude.Eq, ReadPrec [GetCSVHeaderResponse]
ReadPrec GetCSVHeaderResponse
Int -> ReadS GetCSVHeaderResponse
ReadS [GetCSVHeaderResponse]
(Int -> ReadS GetCSVHeaderResponse)
-> ReadS [GetCSVHeaderResponse]
-> ReadPrec GetCSVHeaderResponse
-> ReadPrec [GetCSVHeaderResponse]
-> Read GetCSVHeaderResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCSVHeaderResponse]
$creadListPrec :: ReadPrec [GetCSVHeaderResponse]
readPrec :: ReadPrec GetCSVHeaderResponse
$creadPrec :: ReadPrec GetCSVHeaderResponse
readList :: ReadS [GetCSVHeaderResponse]
$creadList :: ReadS [GetCSVHeaderResponse]
readsPrec :: Int -> ReadS GetCSVHeaderResponse
$creadsPrec :: Int -> ReadS GetCSVHeaderResponse
Prelude.Read, Int -> GetCSVHeaderResponse -> ShowS
[GetCSVHeaderResponse] -> ShowS
GetCSVHeaderResponse -> String
(Int -> GetCSVHeaderResponse -> ShowS)
-> (GetCSVHeaderResponse -> String)
-> ([GetCSVHeaderResponse] -> ShowS)
-> Show GetCSVHeaderResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCSVHeaderResponse] -> ShowS
$cshowList :: [GetCSVHeaderResponse] -> ShowS
show :: GetCSVHeaderResponse -> String
$cshow :: GetCSVHeaderResponse -> String
showsPrec :: Int -> GetCSVHeaderResponse -> ShowS
$cshowsPrec :: Int -> GetCSVHeaderResponse -> ShowS
Prelude.Show, (forall x. GetCSVHeaderResponse -> Rep GetCSVHeaderResponse x)
-> (forall x. Rep GetCSVHeaderResponse x -> GetCSVHeaderResponse)
-> Generic GetCSVHeaderResponse
forall x. Rep GetCSVHeaderResponse x -> GetCSVHeaderResponse
forall x. GetCSVHeaderResponse -> Rep GetCSVHeaderResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCSVHeaderResponse x -> GetCSVHeaderResponse
$cfrom :: forall x. GetCSVHeaderResponse -> Rep GetCSVHeaderResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetCSVHeaderResponse' 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', 'getCSVHeaderResponse_userPoolId' - The user pool ID for the user pool that the users are to be imported
-- into.
--
-- 'cSVHeader', 'getCSVHeaderResponse_cSVHeader' - The header information for the .csv file for the user import job.
--
-- 'httpStatus', 'getCSVHeaderResponse_httpStatus' - The response's http status code.
newGetCSVHeaderResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetCSVHeaderResponse
newGetCSVHeaderResponse :: Int -> GetCSVHeaderResponse
newGetCSVHeaderResponse Int
pHttpStatus_ =
  GetCSVHeaderResponse' :: Maybe Text -> Maybe [Text] -> Int -> GetCSVHeaderResponse
GetCSVHeaderResponse'
    { $sel:userPoolId:GetCSVHeaderResponse' :: Maybe Text
userPoolId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:cSVHeader:GetCSVHeaderResponse' :: Maybe [Text]
cSVHeader = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetCSVHeaderResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

-- | The header information for the .csv file for the user import job.
getCSVHeaderResponse_cSVHeader :: Lens.Lens' GetCSVHeaderResponse (Prelude.Maybe [Prelude.Text])
getCSVHeaderResponse_cSVHeader :: (Maybe [Text] -> f (Maybe [Text]))
-> GetCSVHeaderResponse -> f GetCSVHeaderResponse
getCSVHeaderResponse_cSVHeader = (GetCSVHeaderResponse -> Maybe [Text])
-> (GetCSVHeaderResponse -> Maybe [Text] -> GetCSVHeaderResponse)
-> Lens
     GetCSVHeaderResponse
     GetCSVHeaderResponse
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCSVHeaderResponse' {Maybe [Text]
cSVHeader :: Maybe [Text]
$sel:cSVHeader:GetCSVHeaderResponse' :: GetCSVHeaderResponse -> Maybe [Text]
cSVHeader} -> Maybe [Text]
cSVHeader) (\s :: GetCSVHeaderResponse
s@GetCSVHeaderResponse' {} Maybe [Text]
a -> GetCSVHeaderResponse
s {$sel:cSVHeader:GetCSVHeaderResponse' :: Maybe [Text]
cSVHeader = Maybe [Text]
a} :: GetCSVHeaderResponse) ((Maybe [Text] -> f (Maybe [Text]))
 -> GetCSVHeaderResponse -> f GetCSVHeaderResponse)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> GetCSVHeaderResponse
-> f GetCSVHeaderResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetCSVHeaderResponse