{-# 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.CognitoSync.RegisterDevice
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Registers a device to receive push sync notifications.
--
-- This API can only be called with temporary credentials provided by
-- Cognito Identity. You cannot call this API with developer credentials.
module Amazonka.CognitoSync.RegisterDevice
  ( -- * Creating a Request
    RegisterDevice (..),
    newRegisterDevice,

    -- * Request Lenses
    registerDevice_identityPoolId,
    registerDevice_identityId,
    registerDevice_platform,
    registerDevice_token,

    -- * Destructuring the Response
    RegisterDeviceResponse (..),
    newRegisterDeviceResponse,

    -- * Response Lenses
    registerDeviceResponse_deviceId,
    registerDeviceResponse_httpStatus,
  )
where

import Amazonka.CognitoSync.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

-- | A request to RegisterDevice.
--
-- /See:/ 'newRegisterDevice' smart constructor.
data RegisterDevice = RegisterDevice'
  { -- | A name-spaced GUID (for example,
    -- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
    -- Cognito. Here, the ID of the pool that the identity belongs to.
    RegisterDevice -> Text
identityPoolId :: Prelude.Text,
    -- | The unique ID for this identity.
    RegisterDevice -> Text
identityId :: Prelude.Text,
    -- | The SNS platform type (e.g. GCM, SDM, APNS, APNS_SANDBOX).
    RegisterDevice -> Platform
platform :: Platform,
    -- | The push token.
    RegisterDevice -> Text
token :: Prelude.Text
  }
  deriving (RegisterDevice -> RegisterDevice -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterDevice -> RegisterDevice -> Bool
$c/= :: RegisterDevice -> RegisterDevice -> Bool
== :: RegisterDevice -> RegisterDevice -> Bool
$c== :: RegisterDevice -> RegisterDevice -> Bool
Prelude.Eq, ReadPrec [RegisterDevice]
ReadPrec RegisterDevice
Int -> ReadS RegisterDevice
ReadS [RegisterDevice]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterDevice]
$creadListPrec :: ReadPrec [RegisterDevice]
readPrec :: ReadPrec RegisterDevice
$creadPrec :: ReadPrec RegisterDevice
readList :: ReadS [RegisterDevice]
$creadList :: ReadS [RegisterDevice]
readsPrec :: Int -> ReadS RegisterDevice
$creadsPrec :: Int -> ReadS RegisterDevice
Prelude.Read, Int -> RegisterDevice -> ShowS
[RegisterDevice] -> ShowS
RegisterDevice -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterDevice] -> ShowS
$cshowList :: [RegisterDevice] -> ShowS
show :: RegisterDevice -> String
$cshow :: RegisterDevice -> String
showsPrec :: Int -> RegisterDevice -> ShowS
$cshowsPrec :: Int -> RegisterDevice -> ShowS
Prelude.Show, forall x. Rep RegisterDevice x -> RegisterDevice
forall x. RegisterDevice -> Rep RegisterDevice x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterDevice x -> RegisterDevice
$cfrom :: forall x. RegisterDevice -> Rep RegisterDevice x
Prelude.Generic)

-- |
-- Create a value of 'RegisterDevice' 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:
--
-- 'identityPoolId', 'registerDevice_identityPoolId' - A name-spaced GUID (for example,
-- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
-- Cognito. Here, the ID of the pool that the identity belongs to.
--
-- 'identityId', 'registerDevice_identityId' - The unique ID for this identity.
--
-- 'platform', 'registerDevice_platform' - The SNS platform type (e.g. GCM, SDM, APNS, APNS_SANDBOX).
--
-- 'token', 'registerDevice_token' - The push token.
newRegisterDevice ::
  -- | 'identityPoolId'
  Prelude.Text ->
  -- | 'identityId'
  Prelude.Text ->
  -- | 'platform'
  Platform ->
  -- | 'token'
  Prelude.Text ->
  RegisterDevice
newRegisterDevice :: Text -> Text -> Platform -> Text -> RegisterDevice
newRegisterDevice
  Text
pIdentityPoolId_
  Text
pIdentityId_
  Platform
pPlatform_
  Text
pToken_ =
    RegisterDevice'
      { $sel:identityPoolId:RegisterDevice' :: Text
identityPoolId = Text
pIdentityPoolId_,
        $sel:identityId:RegisterDevice' :: Text
identityId = Text
pIdentityId_,
        $sel:platform:RegisterDevice' :: Platform
platform = Platform
pPlatform_,
        $sel:token:RegisterDevice' :: Text
token = Text
pToken_
      }

-- | A name-spaced GUID (for example,
-- us-east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
-- Cognito. Here, the ID of the pool that the identity belongs to.
registerDevice_identityPoolId :: Lens.Lens' RegisterDevice Prelude.Text
registerDevice_identityPoolId :: Lens' RegisterDevice Text
registerDevice_identityPoolId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterDevice' {Text
identityPoolId :: Text
$sel:identityPoolId:RegisterDevice' :: RegisterDevice -> Text
identityPoolId} -> Text
identityPoolId) (\s :: RegisterDevice
s@RegisterDevice' {} Text
a -> RegisterDevice
s {$sel:identityPoolId:RegisterDevice' :: Text
identityPoolId = Text
a} :: RegisterDevice)

-- | The unique ID for this identity.
registerDevice_identityId :: Lens.Lens' RegisterDevice Prelude.Text
registerDevice_identityId :: Lens' RegisterDevice Text
registerDevice_identityId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterDevice' {Text
identityId :: Text
$sel:identityId:RegisterDevice' :: RegisterDevice -> Text
identityId} -> Text
identityId) (\s :: RegisterDevice
s@RegisterDevice' {} Text
a -> RegisterDevice
s {$sel:identityId:RegisterDevice' :: Text
identityId = Text
a} :: RegisterDevice)

-- | The SNS platform type (e.g. GCM, SDM, APNS, APNS_SANDBOX).
registerDevice_platform :: Lens.Lens' RegisterDevice Platform
registerDevice_platform :: Lens' RegisterDevice Platform
registerDevice_platform = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterDevice' {Platform
platform :: Platform
$sel:platform:RegisterDevice' :: RegisterDevice -> Platform
platform} -> Platform
platform) (\s :: RegisterDevice
s@RegisterDevice' {} Platform
a -> RegisterDevice
s {$sel:platform:RegisterDevice' :: Platform
platform = Platform
a} :: RegisterDevice)

-- | The push token.
registerDevice_token :: Lens.Lens' RegisterDevice Prelude.Text
registerDevice_token :: Lens' RegisterDevice Text
registerDevice_token = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterDevice' {Text
token :: Text
$sel:token:RegisterDevice' :: RegisterDevice -> Text
token} -> Text
token) (\s :: RegisterDevice
s@RegisterDevice' {} Text
a -> RegisterDevice
s {$sel:token:RegisterDevice' :: Text
token = Text
a} :: RegisterDevice)

instance Core.AWSRequest RegisterDevice where
  type
    AWSResponse RegisterDevice =
      RegisterDeviceResponse
  request :: (Service -> Service) -> RegisterDevice -> Request RegisterDevice
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 RegisterDevice
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RegisterDevice)))
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 Text -> Int -> RegisterDeviceResponse
RegisterDeviceResponse'
            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
"DeviceId")
            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 RegisterDevice where
  hashWithSalt :: Int -> RegisterDevice -> Int
hashWithSalt Int
_salt RegisterDevice' {Text
Platform
token :: Text
platform :: Platform
identityId :: Text
identityPoolId :: Text
$sel:token:RegisterDevice' :: RegisterDevice -> Text
$sel:platform:RegisterDevice' :: RegisterDevice -> Platform
$sel:identityId:RegisterDevice' :: RegisterDevice -> Text
$sel:identityPoolId:RegisterDevice' :: RegisterDevice -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
identityPoolId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
identityId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Platform
platform
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
token

instance Prelude.NFData RegisterDevice where
  rnf :: RegisterDevice -> ()
rnf RegisterDevice' {Text
Platform
token :: Text
platform :: Platform
identityId :: Text
identityPoolId :: Text
$sel:token:RegisterDevice' :: RegisterDevice -> Text
$sel:platform:RegisterDevice' :: RegisterDevice -> Platform
$sel:identityId:RegisterDevice' :: RegisterDevice -> Text
$sel:identityPoolId:RegisterDevice' :: RegisterDevice -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
identityPoolId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
identityId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Platform
platform
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
token

instance Data.ToHeaders RegisterDevice where
  toHeaders :: RegisterDevice -> 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 RegisterDevice where
  toJSON :: RegisterDevice -> Value
toJSON RegisterDevice' {Text
Platform
token :: Text
platform :: Platform
identityId :: Text
identityPoolId :: Text
$sel:token:RegisterDevice' :: RegisterDevice -> Text
$sel:platform:RegisterDevice' :: RegisterDevice -> Platform
$sel:identityId:RegisterDevice' :: RegisterDevice -> Text
$sel:identityPoolId:RegisterDevice' :: RegisterDevice -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Platform" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Platform
platform),
            forall a. a -> Maybe a
Prelude.Just (Key
"Token" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
token)
          ]
      )

instance Data.ToPath RegisterDevice where
  toPath :: RegisterDevice -> ByteString
toPath RegisterDevice' {Text
Platform
token :: Text
platform :: Platform
identityId :: Text
identityPoolId :: Text
$sel:token:RegisterDevice' :: RegisterDevice -> Text
$sel:platform:RegisterDevice' :: RegisterDevice -> Platform
$sel:identityId:RegisterDevice' :: RegisterDevice -> Text
$sel:identityPoolId:RegisterDevice' :: RegisterDevice -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/identitypools/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
identityPoolId,
        ByteString
"/identity/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
identityId,
        ByteString
"/device"
      ]

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

-- | Response to a RegisterDevice request.
--
-- /See:/ 'newRegisterDeviceResponse' smart constructor.
data RegisterDeviceResponse = RegisterDeviceResponse'
  { -- | The unique ID generated for this device by Cognito.
    RegisterDeviceResponse -> Maybe Text
deviceId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    RegisterDeviceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (RegisterDeviceResponse -> RegisterDeviceResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterDeviceResponse -> RegisterDeviceResponse -> Bool
$c/= :: RegisterDeviceResponse -> RegisterDeviceResponse -> Bool
== :: RegisterDeviceResponse -> RegisterDeviceResponse -> Bool
$c== :: RegisterDeviceResponse -> RegisterDeviceResponse -> Bool
Prelude.Eq, ReadPrec [RegisterDeviceResponse]
ReadPrec RegisterDeviceResponse
Int -> ReadS RegisterDeviceResponse
ReadS [RegisterDeviceResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterDeviceResponse]
$creadListPrec :: ReadPrec [RegisterDeviceResponse]
readPrec :: ReadPrec RegisterDeviceResponse
$creadPrec :: ReadPrec RegisterDeviceResponse
readList :: ReadS [RegisterDeviceResponse]
$creadList :: ReadS [RegisterDeviceResponse]
readsPrec :: Int -> ReadS RegisterDeviceResponse
$creadsPrec :: Int -> ReadS RegisterDeviceResponse
Prelude.Read, Int -> RegisterDeviceResponse -> ShowS
[RegisterDeviceResponse] -> ShowS
RegisterDeviceResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterDeviceResponse] -> ShowS
$cshowList :: [RegisterDeviceResponse] -> ShowS
show :: RegisterDeviceResponse -> String
$cshow :: RegisterDeviceResponse -> String
showsPrec :: Int -> RegisterDeviceResponse -> ShowS
$cshowsPrec :: Int -> RegisterDeviceResponse -> ShowS
Prelude.Show, forall x. Rep RegisterDeviceResponse x -> RegisterDeviceResponse
forall x. RegisterDeviceResponse -> Rep RegisterDeviceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterDeviceResponse x -> RegisterDeviceResponse
$cfrom :: forall x. RegisterDeviceResponse -> Rep RegisterDeviceResponse x
Prelude.Generic)

-- |
-- Create a value of 'RegisterDeviceResponse' 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:
--
-- 'deviceId', 'registerDeviceResponse_deviceId' - The unique ID generated for this device by Cognito.
--
-- 'httpStatus', 'registerDeviceResponse_httpStatus' - The response's http status code.
newRegisterDeviceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RegisterDeviceResponse
newRegisterDeviceResponse :: Int -> RegisterDeviceResponse
newRegisterDeviceResponse Int
pHttpStatus_ =
  RegisterDeviceResponse'
    { $sel:deviceId:RegisterDeviceResponse' :: Maybe Text
deviceId = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RegisterDeviceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The unique ID generated for this device by Cognito.
registerDeviceResponse_deviceId :: Lens.Lens' RegisterDeviceResponse (Prelude.Maybe Prelude.Text)
registerDeviceResponse_deviceId :: Lens' RegisterDeviceResponse (Maybe Text)
registerDeviceResponse_deviceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterDeviceResponse' {Maybe Text
deviceId :: Maybe Text
$sel:deviceId:RegisterDeviceResponse' :: RegisterDeviceResponse -> Maybe Text
deviceId} -> Maybe Text
deviceId) (\s :: RegisterDeviceResponse
s@RegisterDeviceResponse' {} Maybe Text
a -> RegisterDeviceResponse
s {$sel:deviceId:RegisterDeviceResponse' :: Maybe Text
deviceId = Maybe Text
a} :: RegisterDeviceResponse)

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

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