{-# 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.Pinpoint.GetSegment
-- 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)
--
-- Retrieves information about the configuration, dimension, and other
-- settings for a specific segment that\'s associated with an application.
module Amazonka.Pinpoint.GetSegment
  ( -- * Creating a Request
    GetSegment (..),
    newGetSegment,

    -- * Request Lenses
    getSegment_segmentId,
    getSegment_applicationId,

    -- * Destructuring the Response
    GetSegmentResponse (..),
    newGetSegmentResponse,

    -- * Response Lenses
    getSegmentResponse_httpStatus,
    getSegmentResponse_segmentResponse,
  )
where

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

-- | /See:/ 'newGetSegment' smart constructor.
data GetSegment = GetSegment'
  { -- | The unique identifier for the segment.
    GetSegment -> Text
segmentId :: Prelude.Text,
    -- | The unique identifier for the application. This identifier is displayed
    -- as the __Project ID__ on the Amazon Pinpoint console.
    GetSegment -> Text
applicationId :: Prelude.Text
  }
  deriving (GetSegment -> GetSegment -> Bool
(GetSegment -> GetSegment -> Bool)
-> (GetSegment -> GetSegment -> Bool) -> Eq GetSegment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetSegment -> GetSegment -> Bool
$c/= :: GetSegment -> GetSegment -> Bool
== :: GetSegment -> GetSegment -> Bool
$c== :: GetSegment -> GetSegment -> Bool
Prelude.Eq, ReadPrec [GetSegment]
ReadPrec GetSegment
Int -> ReadS GetSegment
ReadS [GetSegment]
(Int -> ReadS GetSegment)
-> ReadS [GetSegment]
-> ReadPrec GetSegment
-> ReadPrec [GetSegment]
-> Read GetSegment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetSegment]
$creadListPrec :: ReadPrec [GetSegment]
readPrec :: ReadPrec GetSegment
$creadPrec :: ReadPrec GetSegment
readList :: ReadS [GetSegment]
$creadList :: ReadS [GetSegment]
readsPrec :: Int -> ReadS GetSegment
$creadsPrec :: Int -> ReadS GetSegment
Prelude.Read, Int -> GetSegment -> ShowS
[GetSegment] -> ShowS
GetSegment -> String
(Int -> GetSegment -> ShowS)
-> (GetSegment -> String)
-> ([GetSegment] -> ShowS)
-> Show GetSegment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetSegment] -> ShowS
$cshowList :: [GetSegment] -> ShowS
show :: GetSegment -> String
$cshow :: GetSegment -> String
showsPrec :: Int -> GetSegment -> ShowS
$cshowsPrec :: Int -> GetSegment -> ShowS
Prelude.Show, (forall x. GetSegment -> Rep GetSegment x)
-> (forall x. Rep GetSegment x -> GetSegment) -> Generic GetSegment
forall x. Rep GetSegment x -> GetSegment
forall x. GetSegment -> Rep GetSegment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetSegment x -> GetSegment
$cfrom :: forall x. GetSegment -> Rep GetSegment x
Prelude.Generic)

-- |
-- Create a value of 'GetSegment' 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:
--
-- 'segmentId', 'getSegment_segmentId' - The unique identifier for the segment.
--
-- 'applicationId', 'getSegment_applicationId' - The unique identifier for the application. This identifier is displayed
-- as the __Project ID__ on the Amazon Pinpoint console.
newGetSegment ::
  -- | 'segmentId'
  Prelude.Text ->
  -- | 'applicationId'
  Prelude.Text ->
  GetSegment
newGetSegment :: Text -> Text -> GetSegment
newGetSegment Text
pSegmentId_ Text
pApplicationId_ =
  GetSegment' :: Text -> Text -> GetSegment
GetSegment'
    { $sel:segmentId:GetSegment' :: Text
segmentId = Text
pSegmentId_,
      $sel:applicationId:GetSegment' :: Text
applicationId = Text
pApplicationId_
    }

-- | The unique identifier for the segment.
getSegment_segmentId :: Lens.Lens' GetSegment Prelude.Text
getSegment_segmentId :: (Text -> f Text) -> GetSegment -> f GetSegment
getSegment_segmentId = (GetSegment -> Text)
-> (GetSegment -> Text -> GetSegment)
-> Lens GetSegment GetSegment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetSegment' {Text
segmentId :: Text
$sel:segmentId:GetSegment' :: GetSegment -> Text
segmentId} -> Text
segmentId) (\s :: GetSegment
s@GetSegment' {} Text
a -> GetSegment
s {$sel:segmentId:GetSegment' :: Text
segmentId = Text
a} :: GetSegment)

-- | The unique identifier for the application. This identifier is displayed
-- as the __Project ID__ on the Amazon Pinpoint console.
getSegment_applicationId :: Lens.Lens' GetSegment Prelude.Text
getSegment_applicationId :: (Text -> f Text) -> GetSegment -> f GetSegment
getSegment_applicationId = (GetSegment -> Text)
-> (GetSegment -> Text -> GetSegment)
-> Lens GetSegment GetSegment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetSegment' {Text
applicationId :: Text
$sel:applicationId:GetSegment' :: GetSegment -> Text
applicationId} -> Text
applicationId) (\s :: GetSegment
s@GetSegment' {} Text
a -> GetSegment
s {$sel:applicationId:GetSegment' :: Text
applicationId = Text
a} :: GetSegment)

instance Core.AWSRequest GetSegment where
  type AWSResponse GetSegment = GetSegmentResponse
  request :: GetSegment -> Request GetSegment
request = Service -> GetSegment -> Request GetSegment
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetSegment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetSegment)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetSegment))
-> Logger
-> Service
-> Proxy GetSegment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetSegment)))
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 ->
          Int -> SegmentResponse -> GetSegmentResponse
GetSegmentResponse'
            (Int -> SegmentResponse -> GetSegmentResponse)
-> Either String Int
-> Either String (SegmentResponse -> GetSegmentResponse)
forall (f :: * -> *) a b. Functor 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))
            Either String (SegmentResponse -> GetSegmentResponse)
-> Either String SegmentResponse
-> Either String GetSegmentResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object -> Either String SegmentResponse
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)
      )

instance Prelude.Hashable GetSegment

instance Prelude.NFData GetSegment

instance Core.ToHeaders GetSegment where
  toHeaders :: GetSegment -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetSegment -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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.ToPath GetSegment where
  toPath :: GetSegment -> ByteString
toPath GetSegment' {Text
applicationId :: Text
segmentId :: Text
$sel:applicationId:GetSegment' :: GetSegment -> Text
$sel:segmentId:GetSegment' :: GetSegment -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/v1/apps/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
applicationId,
        ByteString
"/segments/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
segmentId
      ]

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

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

-- |
-- Create a value of 'GetSegmentResponse' 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', 'getSegmentResponse_httpStatus' - The response's http status code.
--
-- 'segmentResponse', 'getSegmentResponse_segmentResponse' - Undocumented member.
newGetSegmentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'segmentResponse'
  SegmentResponse ->
  GetSegmentResponse
newGetSegmentResponse :: Int -> SegmentResponse -> GetSegmentResponse
newGetSegmentResponse Int
pHttpStatus_ SegmentResponse
pSegmentResponse_ =
  GetSegmentResponse' :: Int -> SegmentResponse -> GetSegmentResponse
GetSegmentResponse'
    { $sel:httpStatus:GetSegmentResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:segmentResponse:GetSegmentResponse' :: SegmentResponse
segmentResponse = SegmentResponse
pSegmentResponse_
    }

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

-- | Undocumented member.
getSegmentResponse_segmentResponse :: Lens.Lens' GetSegmentResponse SegmentResponse
getSegmentResponse_segmentResponse :: (SegmentResponse -> f SegmentResponse)
-> GetSegmentResponse -> f GetSegmentResponse
getSegmentResponse_segmentResponse = (GetSegmentResponse -> SegmentResponse)
-> (GetSegmentResponse -> SegmentResponse -> GetSegmentResponse)
-> Lens
     GetSegmentResponse
     GetSegmentResponse
     SegmentResponse
     SegmentResponse
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetSegmentResponse' {SegmentResponse
segmentResponse :: SegmentResponse
$sel:segmentResponse:GetSegmentResponse' :: GetSegmentResponse -> SegmentResponse
segmentResponse} -> SegmentResponse
segmentResponse) (\s :: GetSegmentResponse
s@GetSegmentResponse' {} SegmentResponse
a -> GetSegmentResponse
s {$sel:segmentResponse:GetSegmentResponse' :: SegmentResponse
segmentResponse = SegmentResponse
a} :: GetSegmentResponse)

instance Prelude.NFData GetSegmentResponse