{-# 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.Personalize.DescribeCampaign
-- 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)
--
-- Describes the given campaign, including its status.
--
-- A campaign can be in one of the following states:
--
-- -   CREATE PENDING > CREATE IN_PROGRESS > ACTIVE -or- CREATE FAILED
--
-- -   DELETE PENDING > DELETE IN_PROGRESS
--
-- When the @status@ is @CREATE FAILED@, the response includes the
-- @failureReason@ key, which describes why.
--
-- For more information on campaigns, see CreateCampaign.
module Amazonka.Personalize.DescribeCampaign
  ( -- * Creating a Request
    DescribeCampaign (..),
    newDescribeCampaign,

    -- * Request Lenses
    describeCampaign_campaignArn,

    -- * Destructuring the Response
    DescribeCampaignResponse (..),
    newDescribeCampaignResponse,

    -- * Response Lenses
    describeCampaignResponse_campaign,
    describeCampaignResponse_httpStatus,
  )
where

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

-- | /See:/ 'newDescribeCampaign' smart constructor.
data DescribeCampaign = DescribeCampaign'
  { -- | The Amazon Resource Name (ARN) of the campaign.
    DescribeCampaign -> Text
campaignArn :: Prelude.Text
  }
  deriving (DescribeCampaign -> DescribeCampaign -> Bool
(DescribeCampaign -> DescribeCampaign -> Bool)
-> (DescribeCampaign -> DescribeCampaign -> Bool)
-> Eq DescribeCampaign
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeCampaign -> DescribeCampaign -> Bool
$c/= :: DescribeCampaign -> DescribeCampaign -> Bool
== :: DescribeCampaign -> DescribeCampaign -> Bool
$c== :: DescribeCampaign -> DescribeCampaign -> Bool
Prelude.Eq, ReadPrec [DescribeCampaign]
ReadPrec DescribeCampaign
Int -> ReadS DescribeCampaign
ReadS [DescribeCampaign]
(Int -> ReadS DescribeCampaign)
-> ReadS [DescribeCampaign]
-> ReadPrec DescribeCampaign
-> ReadPrec [DescribeCampaign]
-> Read DescribeCampaign
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeCampaign]
$creadListPrec :: ReadPrec [DescribeCampaign]
readPrec :: ReadPrec DescribeCampaign
$creadPrec :: ReadPrec DescribeCampaign
readList :: ReadS [DescribeCampaign]
$creadList :: ReadS [DescribeCampaign]
readsPrec :: Int -> ReadS DescribeCampaign
$creadsPrec :: Int -> ReadS DescribeCampaign
Prelude.Read, Int -> DescribeCampaign -> ShowS
[DescribeCampaign] -> ShowS
DescribeCampaign -> String
(Int -> DescribeCampaign -> ShowS)
-> (DescribeCampaign -> String)
-> ([DescribeCampaign] -> ShowS)
-> Show DescribeCampaign
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeCampaign] -> ShowS
$cshowList :: [DescribeCampaign] -> ShowS
show :: DescribeCampaign -> String
$cshow :: DescribeCampaign -> String
showsPrec :: Int -> DescribeCampaign -> ShowS
$cshowsPrec :: Int -> DescribeCampaign -> ShowS
Prelude.Show, (forall x. DescribeCampaign -> Rep DescribeCampaign x)
-> (forall x. Rep DescribeCampaign x -> DescribeCampaign)
-> Generic DescribeCampaign
forall x. Rep DescribeCampaign x -> DescribeCampaign
forall x. DescribeCampaign -> Rep DescribeCampaign x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeCampaign x -> DescribeCampaign
$cfrom :: forall x. DescribeCampaign -> Rep DescribeCampaign x
Prelude.Generic)

-- |
-- Create a value of 'DescribeCampaign' 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:
--
-- 'campaignArn', 'describeCampaign_campaignArn' - The Amazon Resource Name (ARN) of the campaign.
newDescribeCampaign ::
  -- | 'campaignArn'
  Prelude.Text ->
  DescribeCampaign
newDescribeCampaign :: Text -> DescribeCampaign
newDescribeCampaign Text
pCampaignArn_ =
  DescribeCampaign' :: Text -> DescribeCampaign
DescribeCampaign' {$sel:campaignArn:DescribeCampaign' :: Text
campaignArn = Text
pCampaignArn_}

-- | The Amazon Resource Name (ARN) of the campaign.
describeCampaign_campaignArn :: Lens.Lens' DescribeCampaign Prelude.Text
describeCampaign_campaignArn :: (Text -> f Text) -> DescribeCampaign -> f DescribeCampaign
describeCampaign_campaignArn = (DescribeCampaign -> Text)
-> (DescribeCampaign -> Text -> DescribeCampaign)
-> Lens DescribeCampaign DescribeCampaign Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeCampaign' {Text
campaignArn :: Text
$sel:campaignArn:DescribeCampaign' :: DescribeCampaign -> Text
campaignArn} -> Text
campaignArn) (\s :: DescribeCampaign
s@DescribeCampaign' {} Text
a -> DescribeCampaign
s {$sel:campaignArn:DescribeCampaign' :: Text
campaignArn = Text
a} :: DescribeCampaign)

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

instance Prelude.NFData DescribeCampaign

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

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

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

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

-- |
-- Create a value of 'DescribeCampaignResponse' 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:
--
-- 'campaign', 'describeCampaignResponse_campaign' - The properties of the campaign.
--
-- 'httpStatus', 'describeCampaignResponse_httpStatus' - The response's http status code.
newDescribeCampaignResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeCampaignResponse
newDescribeCampaignResponse :: Int -> DescribeCampaignResponse
newDescribeCampaignResponse Int
pHttpStatus_ =
  DescribeCampaignResponse' :: Maybe Campaign -> Int -> DescribeCampaignResponse
DescribeCampaignResponse'
    { $sel:campaign:DescribeCampaignResponse' :: Maybe Campaign
campaign =
        Maybe Campaign
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeCampaignResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The properties of the campaign.
describeCampaignResponse_campaign :: Lens.Lens' DescribeCampaignResponse (Prelude.Maybe Campaign)
describeCampaignResponse_campaign :: (Maybe Campaign -> f (Maybe Campaign))
-> DescribeCampaignResponse -> f DescribeCampaignResponse
describeCampaignResponse_campaign = (DescribeCampaignResponse -> Maybe Campaign)
-> (DescribeCampaignResponse
    -> Maybe Campaign -> DescribeCampaignResponse)
-> Lens
     DescribeCampaignResponse
     DescribeCampaignResponse
     (Maybe Campaign)
     (Maybe Campaign)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeCampaignResponse' {Maybe Campaign
campaign :: Maybe Campaign
$sel:campaign:DescribeCampaignResponse' :: DescribeCampaignResponse -> Maybe Campaign
campaign} -> Maybe Campaign
campaign) (\s :: DescribeCampaignResponse
s@DescribeCampaignResponse' {} Maybe Campaign
a -> DescribeCampaignResponse
s {$sel:campaign:DescribeCampaignResponse' :: Maybe Campaign
campaign = Maybe Campaign
a} :: DescribeCampaignResponse)

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

instance Prelude.NFData DescribeCampaignResponse