{-# 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.MediaConnect.PurchaseOffering
-- 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)
--
-- Submits a request to purchase an offering. If you already have an active
-- reservation, you can\'t purchase another offering.
module Amazonka.MediaConnect.PurchaseOffering
  ( -- * Creating a Request
    PurchaseOffering (..),
    newPurchaseOffering,

    -- * Request Lenses
    purchaseOffering_offeringArn,
    purchaseOffering_start,
    purchaseOffering_reservationName,

    -- * Destructuring the Response
    PurchaseOfferingResponse (..),
    newPurchaseOfferingResponse,

    -- * Response Lenses
    purchaseOfferingResponse_reservation,
    purchaseOfferingResponse_httpStatus,
  )
where

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

-- | A request to purchase a offering.
--
-- /See:/ 'newPurchaseOffering' smart constructor.
data PurchaseOffering = PurchaseOffering'
  { -- | The Amazon Resource Name (ARN) of the offering.
    PurchaseOffering -> Text
offeringArn :: Prelude.Text,
    -- | The date and time that you want the reservation to begin, in Coordinated
    -- Universal Time (UTC). You can specify any date and time between 12:00am
    -- on the first day of the current month to the current time on today\'s
    -- date, inclusive. Specify the start in a 24-hour notation. Use the
    -- following format: YYYY-MM-DDTHH:mm:SSZ, where T and Z are literal
    -- characters. For example, to specify 11:30pm on March 5, 2020, enter
    -- 2020-03-05T23:30:00Z.
    PurchaseOffering -> Text
start :: Prelude.Text,
    -- | The name that you want to use for the reservation.
    PurchaseOffering -> Text
reservationName :: Prelude.Text
  }
  deriving (PurchaseOffering -> PurchaseOffering -> Bool
(PurchaseOffering -> PurchaseOffering -> Bool)
-> (PurchaseOffering -> PurchaseOffering -> Bool)
-> Eq PurchaseOffering
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PurchaseOffering -> PurchaseOffering -> Bool
$c/= :: PurchaseOffering -> PurchaseOffering -> Bool
== :: PurchaseOffering -> PurchaseOffering -> Bool
$c== :: PurchaseOffering -> PurchaseOffering -> Bool
Prelude.Eq, ReadPrec [PurchaseOffering]
ReadPrec PurchaseOffering
Int -> ReadS PurchaseOffering
ReadS [PurchaseOffering]
(Int -> ReadS PurchaseOffering)
-> ReadS [PurchaseOffering]
-> ReadPrec PurchaseOffering
-> ReadPrec [PurchaseOffering]
-> Read PurchaseOffering
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PurchaseOffering]
$creadListPrec :: ReadPrec [PurchaseOffering]
readPrec :: ReadPrec PurchaseOffering
$creadPrec :: ReadPrec PurchaseOffering
readList :: ReadS [PurchaseOffering]
$creadList :: ReadS [PurchaseOffering]
readsPrec :: Int -> ReadS PurchaseOffering
$creadsPrec :: Int -> ReadS PurchaseOffering
Prelude.Read, Int -> PurchaseOffering -> ShowS
[PurchaseOffering] -> ShowS
PurchaseOffering -> String
(Int -> PurchaseOffering -> ShowS)
-> (PurchaseOffering -> String)
-> ([PurchaseOffering] -> ShowS)
-> Show PurchaseOffering
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PurchaseOffering] -> ShowS
$cshowList :: [PurchaseOffering] -> ShowS
show :: PurchaseOffering -> String
$cshow :: PurchaseOffering -> String
showsPrec :: Int -> PurchaseOffering -> ShowS
$cshowsPrec :: Int -> PurchaseOffering -> ShowS
Prelude.Show, (forall x. PurchaseOffering -> Rep PurchaseOffering x)
-> (forall x. Rep PurchaseOffering x -> PurchaseOffering)
-> Generic PurchaseOffering
forall x. Rep PurchaseOffering x -> PurchaseOffering
forall x. PurchaseOffering -> Rep PurchaseOffering x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PurchaseOffering x -> PurchaseOffering
$cfrom :: forall x. PurchaseOffering -> Rep PurchaseOffering x
Prelude.Generic)

-- |
-- Create a value of 'PurchaseOffering' 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:
--
-- 'offeringArn', 'purchaseOffering_offeringArn' - The Amazon Resource Name (ARN) of the offering.
--
-- 'start', 'purchaseOffering_start' - The date and time that you want the reservation to begin, in Coordinated
-- Universal Time (UTC). You can specify any date and time between 12:00am
-- on the first day of the current month to the current time on today\'s
-- date, inclusive. Specify the start in a 24-hour notation. Use the
-- following format: YYYY-MM-DDTHH:mm:SSZ, where T and Z are literal
-- characters. For example, to specify 11:30pm on March 5, 2020, enter
-- 2020-03-05T23:30:00Z.
--
-- 'reservationName', 'purchaseOffering_reservationName' - The name that you want to use for the reservation.
newPurchaseOffering ::
  -- | 'offeringArn'
  Prelude.Text ->
  -- | 'start'
  Prelude.Text ->
  -- | 'reservationName'
  Prelude.Text ->
  PurchaseOffering
newPurchaseOffering :: Text -> Text -> Text -> PurchaseOffering
newPurchaseOffering
  Text
pOfferingArn_
  Text
pStart_
  Text
pReservationName_ =
    PurchaseOffering' :: Text -> Text -> Text -> PurchaseOffering
PurchaseOffering'
      { $sel:offeringArn:PurchaseOffering' :: Text
offeringArn = Text
pOfferingArn_,
        $sel:start:PurchaseOffering' :: Text
start = Text
pStart_,
        $sel:reservationName:PurchaseOffering' :: Text
reservationName = Text
pReservationName_
      }

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

-- | The date and time that you want the reservation to begin, in Coordinated
-- Universal Time (UTC). You can specify any date and time between 12:00am
-- on the first day of the current month to the current time on today\'s
-- date, inclusive. Specify the start in a 24-hour notation. Use the
-- following format: YYYY-MM-DDTHH:mm:SSZ, where T and Z are literal
-- characters. For example, to specify 11:30pm on March 5, 2020, enter
-- 2020-03-05T23:30:00Z.
purchaseOffering_start :: Lens.Lens' PurchaseOffering Prelude.Text
purchaseOffering_start :: (Text -> f Text) -> PurchaseOffering -> f PurchaseOffering
purchaseOffering_start = (PurchaseOffering -> Text)
-> (PurchaseOffering -> Text -> PurchaseOffering)
-> Lens PurchaseOffering PurchaseOffering Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PurchaseOffering' {Text
start :: Text
$sel:start:PurchaseOffering' :: PurchaseOffering -> Text
start} -> Text
start) (\s :: PurchaseOffering
s@PurchaseOffering' {} Text
a -> PurchaseOffering
s {$sel:start:PurchaseOffering' :: Text
start = Text
a} :: PurchaseOffering)

-- | The name that you want to use for the reservation.
purchaseOffering_reservationName :: Lens.Lens' PurchaseOffering Prelude.Text
purchaseOffering_reservationName :: (Text -> f Text) -> PurchaseOffering -> f PurchaseOffering
purchaseOffering_reservationName = (PurchaseOffering -> Text)
-> (PurchaseOffering -> Text -> PurchaseOffering)
-> Lens PurchaseOffering PurchaseOffering Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PurchaseOffering' {Text
reservationName :: Text
$sel:reservationName:PurchaseOffering' :: PurchaseOffering -> Text
reservationName} -> Text
reservationName) (\s :: PurchaseOffering
s@PurchaseOffering' {} Text
a -> PurchaseOffering
s {$sel:reservationName:PurchaseOffering' :: Text
reservationName = Text
a} :: PurchaseOffering)

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

instance Prelude.NFData PurchaseOffering

instance Core.ToHeaders PurchaseOffering where
  toHeaders :: PurchaseOffering -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PurchaseOffering -> 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 PurchaseOffering where
  toJSON :: PurchaseOffering -> Value
toJSON PurchaseOffering' {Text
reservationName :: Text
start :: Text
offeringArn :: Text
$sel:reservationName:PurchaseOffering' :: PurchaseOffering -> Text
$sel:start:PurchaseOffering' :: PurchaseOffering -> Text
$sel:offeringArn:PurchaseOffering' :: PurchaseOffering -> 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
"start" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
start),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"reservationName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
reservationName)
          ]
      )

instance Core.ToPath PurchaseOffering where
  toPath :: PurchaseOffering -> ByteString
toPath PurchaseOffering' {Text
reservationName :: Text
start :: Text
offeringArn :: Text
$sel:reservationName:PurchaseOffering' :: PurchaseOffering -> Text
$sel:start:PurchaseOffering' :: PurchaseOffering -> Text
$sel:offeringArn:PurchaseOffering' :: PurchaseOffering -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v1/offerings/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
offeringArn]

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

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

-- |
-- Create a value of 'PurchaseOfferingResponse' 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:
--
-- 'reservation', 'purchaseOfferingResponse_reservation' - Undocumented member.
--
-- 'httpStatus', 'purchaseOfferingResponse_httpStatus' - The response's http status code.
newPurchaseOfferingResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PurchaseOfferingResponse
newPurchaseOfferingResponse :: Int -> PurchaseOfferingResponse
newPurchaseOfferingResponse Int
pHttpStatus_ =
  PurchaseOfferingResponse' :: Maybe Reservation -> Int -> PurchaseOfferingResponse
PurchaseOfferingResponse'
    { $sel:reservation:PurchaseOfferingResponse' :: Maybe Reservation
reservation =
        Maybe Reservation
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PurchaseOfferingResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Undocumented member.
purchaseOfferingResponse_reservation :: Lens.Lens' PurchaseOfferingResponse (Prelude.Maybe Reservation)
purchaseOfferingResponse_reservation :: (Maybe Reservation -> f (Maybe Reservation))
-> PurchaseOfferingResponse -> f PurchaseOfferingResponse
purchaseOfferingResponse_reservation = (PurchaseOfferingResponse -> Maybe Reservation)
-> (PurchaseOfferingResponse
    -> Maybe Reservation -> PurchaseOfferingResponse)
-> Lens
     PurchaseOfferingResponse
     PurchaseOfferingResponse
     (Maybe Reservation)
     (Maybe Reservation)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PurchaseOfferingResponse' {Maybe Reservation
reservation :: Maybe Reservation
$sel:reservation:PurchaseOfferingResponse' :: PurchaseOfferingResponse -> Maybe Reservation
reservation} -> Maybe Reservation
reservation) (\s :: PurchaseOfferingResponse
s@PurchaseOfferingResponse' {} Maybe Reservation
a -> PurchaseOfferingResponse
s {$sel:reservation:PurchaseOfferingResponse' :: Maybe Reservation
reservation = Maybe Reservation
a} :: PurchaseOfferingResponse)

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

instance Prelude.NFData PurchaseOfferingResponse