{-# 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.CreateSegment
-- 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)
--
-- Creates a new segment for an application or updates the configuration,
-- dimension, and other settings for an existing segment that\'s associated
-- with an application.
module Amazonka.Pinpoint.CreateSegment
  ( -- * Creating a Request
    CreateSegment (..),
    newCreateSegment,

    -- * Request Lenses
    createSegment_applicationId,
    createSegment_writeSegmentRequest,

    -- * Destructuring the Response
    CreateSegmentResponse (..),
    newCreateSegmentResponse,

    -- * Response Lenses
    createSegmentResponse_httpStatus,
    createSegmentResponse_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:/ 'newCreateSegment' smart constructor.
data CreateSegment = CreateSegment'
  { -- | The unique identifier for the application. This identifier is displayed
    -- as the __Project ID__ on the Amazon Pinpoint console.
    CreateSegment -> Text
applicationId :: Prelude.Text,
    CreateSegment -> WriteSegmentRequest
writeSegmentRequest :: WriteSegmentRequest
  }
  deriving (CreateSegment -> CreateSegment -> Bool
(CreateSegment -> CreateSegment -> Bool)
-> (CreateSegment -> CreateSegment -> Bool) -> Eq CreateSegment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateSegment -> CreateSegment -> Bool
$c/= :: CreateSegment -> CreateSegment -> Bool
== :: CreateSegment -> CreateSegment -> Bool
$c== :: CreateSegment -> CreateSegment -> Bool
Prelude.Eq, ReadPrec [CreateSegment]
ReadPrec CreateSegment
Int -> ReadS CreateSegment
ReadS [CreateSegment]
(Int -> ReadS CreateSegment)
-> ReadS [CreateSegment]
-> ReadPrec CreateSegment
-> ReadPrec [CreateSegment]
-> Read CreateSegment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateSegment]
$creadListPrec :: ReadPrec [CreateSegment]
readPrec :: ReadPrec CreateSegment
$creadPrec :: ReadPrec CreateSegment
readList :: ReadS [CreateSegment]
$creadList :: ReadS [CreateSegment]
readsPrec :: Int -> ReadS CreateSegment
$creadsPrec :: Int -> ReadS CreateSegment
Prelude.Read, Int -> CreateSegment -> ShowS
[CreateSegment] -> ShowS
CreateSegment -> String
(Int -> CreateSegment -> ShowS)
-> (CreateSegment -> String)
-> ([CreateSegment] -> ShowS)
-> Show CreateSegment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateSegment] -> ShowS
$cshowList :: [CreateSegment] -> ShowS
show :: CreateSegment -> String
$cshow :: CreateSegment -> String
showsPrec :: Int -> CreateSegment -> ShowS
$cshowsPrec :: Int -> CreateSegment -> ShowS
Prelude.Show, (forall x. CreateSegment -> Rep CreateSegment x)
-> (forall x. Rep CreateSegment x -> CreateSegment)
-> Generic CreateSegment
forall x. Rep CreateSegment x -> CreateSegment
forall x. CreateSegment -> Rep CreateSegment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateSegment x -> CreateSegment
$cfrom :: forall x. CreateSegment -> Rep CreateSegment x
Prelude.Generic)

-- |
-- Create a value of 'CreateSegment' 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:
--
-- 'applicationId', 'createSegment_applicationId' - The unique identifier for the application. This identifier is displayed
-- as the __Project ID__ on the Amazon Pinpoint console.
--
-- 'writeSegmentRequest', 'createSegment_writeSegmentRequest' - Undocumented member.
newCreateSegment ::
  -- | 'applicationId'
  Prelude.Text ->
  -- | 'writeSegmentRequest'
  WriteSegmentRequest ->
  CreateSegment
newCreateSegment :: Text -> WriteSegmentRequest -> CreateSegment
newCreateSegment
  Text
pApplicationId_
  WriteSegmentRequest
pWriteSegmentRequest_ =
    CreateSegment' :: Text -> WriteSegmentRequest -> CreateSegment
CreateSegment'
      { $sel:applicationId:CreateSegment' :: Text
applicationId = Text
pApplicationId_,
        $sel:writeSegmentRequest:CreateSegment' :: WriteSegmentRequest
writeSegmentRequest = WriteSegmentRequest
pWriteSegmentRequest_
      }

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

-- | Undocumented member.
createSegment_writeSegmentRequest :: Lens.Lens' CreateSegment WriteSegmentRequest
createSegment_writeSegmentRequest :: (WriteSegmentRequest -> f WriteSegmentRequest)
-> CreateSegment -> f CreateSegment
createSegment_writeSegmentRequest = (CreateSegment -> WriteSegmentRequest)
-> (CreateSegment -> WriteSegmentRequest -> CreateSegment)
-> Lens
     CreateSegment CreateSegment WriteSegmentRequest WriteSegmentRequest
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSegment' {WriteSegmentRequest
writeSegmentRequest :: WriteSegmentRequest
$sel:writeSegmentRequest:CreateSegment' :: CreateSegment -> WriteSegmentRequest
writeSegmentRequest} -> WriteSegmentRequest
writeSegmentRequest) (\s :: CreateSegment
s@CreateSegment' {} WriteSegmentRequest
a -> CreateSegment
s {$sel:writeSegmentRequest:CreateSegment' :: WriteSegmentRequest
writeSegmentRequest = WriteSegmentRequest
a} :: CreateSegment)

instance Core.AWSRequest CreateSegment where
  type
    AWSResponse CreateSegment =
      CreateSegmentResponse
  request :: CreateSegment -> Request CreateSegment
request = Service -> CreateSegment -> Request CreateSegment
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateSegment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateSegment)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateSegment))
-> Logger
-> Service
-> Proxy CreateSegment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateSegment)))
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 -> CreateSegmentResponse
CreateSegmentResponse'
            (Int -> SegmentResponse -> CreateSegmentResponse)
-> Either String Int
-> Either String (SegmentResponse -> CreateSegmentResponse)
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 -> CreateSegmentResponse)
-> Either String SegmentResponse
-> Either String CreateSegmentResponse
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 CreateSegment

instance Prelude.NFData CreateSegment

instance Core.ToHeaders CreateSegment where
  toHeaders :: CreateSegment -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateSegment -> 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.ToJSON CreateSegment where
  toJSON :: CreateSegment -> Value
toJSON CreateSegment' {Text
WriteSegmentRequest
writeSegmentRequest :: WriteSegmentRequest
applicationId :: Text
$sel:writeSegmentRequest:CreateSegment' :: CreateSegment -> WriteSegmentRequest
$sel:applicationId:CreateSegment' :: CreateSegment -> 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
"WriteSegmentRequest" Text -> WriteSegmentRequest -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= WriteSegmentRequest
writeSegmentRequest)
          ]
      )

instance Core.ToPath CreateSegment where
  toPath :: CreateSegment -> ByteString
toPath CreateSegment' {Text
WriteSegmentRequest
writeSegmentRequest :: WriteSegmentRequest
applicationId :: Text
$sel:writeSegmentRequest:CreateSegment' :: CreateSegment -> WriteSegmentRequest
$sel:applicationId:CreateSegment' :: CreateSegment -> 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"]

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

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

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

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

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

instance Prelude.NFData CreateSegmentResponse