{-# 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.GrantFlowEntitlements
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Grants entitlements to an existing flow.
module Amazonka.MediaConnect.GrantFlowEntitlements
  ( -- * Creating a Request
    GrantFlowEntitlements (..),
    newGrantFlowEntitlements,

    -- * Request Lenses
    grantFlowEntitlements_flowArn,
    grantFlowEntitlements_entitlements,

    -- * Destructuring the Response
    GrantFlowEntitlementsResponse (..),
    newGrantFlowEntitlementsResponse,

    -- * Response Lenses
    grantFlowEntitlementsResponse_entitlements,
    grantFlowEntitlementsResponse_flowArn,
    grantFlowEntitlementsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 grant entitlements on a flow.
--
-- /See:/ 'newGrantFlowEntitlements' smart constructor.
data GrantFlowEntitlements = GrantFlowEntitlements'
  { -- | The flow that you want to grant entitlements on.
    GrantFlowEntitlements -> Text
flowArn :: Prelude.Text,
    -- | The list of entitlements that you want to grant.
    GrantFlowEntitlements -> [GrantEntitlementRequest]
entitlements :: [GrantEntitlementRequest]
  }
  deriving (GrantFlowEntitlements -> GrantFlowEntitlements -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GrantFlowEntitlements -> GrantFlowEntitlements -> Bool
$c/= :: GrantFlowEntitlements -> GrantFlowEntitlements -> Bool
== :: GrantFlowEntitlements -> GrantFlowEntitlements -> Bool
$c== :: GrantFlowEntitlements -> GrantFlowEntitlements -> Bool
Prelude.Eq, ReadPrec [GrantFlowEntitlements]
ReadPrec GrantFlowEntitlements
Int -> ReadS GrantFlowEntitlements
ReadS [GrantFlowEntitlements]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GrantFlowEntitlements]
$creadListPrec :: ReadPrec [GrantFlowEntitlements]
readPrec :: ReadPrec GrantFlowEntitlements
$creadPrec :: ReadPrec GrantFlowEntitlements
readList :: ReadS [GrantFlowEntitlements]
$creadList :: ReadS [GrantFlowEntitlements]
readsPrec :: Int -> ReadS GrantFlowEntitlements
$creadsPrec :: Int -> ReadS GrantFlowEntitlements
Prelude.Read, Int -> GrantFlowEntitlements -> ShowS
[GrantFlowEntitlements] -> ShowS
GrantFlowEntitlements -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GrantFlowEntitlements] -> ShowS
$cshowList :: [GrantFlowEntitlements] -> ShowS
show :: GrantFlowEntitlements -> String
$cshow :: GrantFlowEntitlements -> String
showsPrec :: Int -> GrantFlowEntitlements -> ShowS
$cshowsPrec :: Int -> GrantFlowEntitlements -> ShowS
Prelude.Show, forall x. Rep GrantFlowEntitlements x -> GrantFlowEntitlements
forall x. GrantFlowEntitlements -> Rep GrantFlowEntitlements x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GrantFlowEntitlements x -> GrantFlowEntitlements
$cfrom :: forall x. GrantFlowEntitlements -> Rep GrantFlowEntitlements x
Prelude.Generic)

-- |
-- Create a value of 'GrantFlowEntitlements' 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:
--
-- 'flowArn', 'grantFlowEntitlements_flowArn' - The flow that you want to grant entitlements on.
--
-- 'entitlements', 'grantFlowEntitlements_entitlements' - The list of entitlements that you want to grant.
newGrantFlowEntitlements ::
  -- | 'flowArn'
  Prelude.Text ->
  GrantFlowEntitlements
newGrantFlowEntitlements :: Text -> GrantFlowEntitlements
newGrantFlowEntitlements Text
pFlowArn_ =
  GrantFlowEntitlements'
    { $sel:flowArn:GrantFlowEntitlements' :: Text
flowArn = Text
pFlowArn_,
      $sel:entitlements:GrantFlowEntitlements' :: [GrantEntitlementRequest]
entitlements = forall a. Monoid a => a
Prelude.mempty
    }

-- | The flow that you want to grant entitlements on.
grantFlowEntitlements_flowArn :: Lens.Lens' GrantFlowEntitlements Prelude.Text
grantFlowEntitlements_flowArn :: Lens' GrantFlowEntitlements Text
grantFlowEntitlements_flowArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrantFlowEntitlements' {Text
flowArn :: Text
$sel:flowArn:GrantFlowEntitlements' :: GrantFlowEntitlements -> Text
flowArn} -> Text
flowArn) (\s :: GrantFlowEntitlements
s@GrantFlowEntitlements' {} Text
a -> GrantFlowEntitlements
s {$sel:flowArn:GrantFlowEntitlements' :: Text
flowArn = Text
a} :: GrantFlowEntitlements)

-- | The list of entitlements that you want to grant.
grantFlowEntitlements_entitlements :: Lens.Lens' GrantFlowEntitlements [GrantEntitlementRequest]
grantFlowEntitlements_entitlements :: Lens' GrantFlowEntitlements [GrantEntitlementRequest]
grantFlowEntitlements_entitlements = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrantFlowEntitlements' {[GrantEntitlementRequest]
entitlements :: [GrantEntitlementRequest]
$sel:entitlements:GrantFlowEntitlements' :: GrantFlowEntitlements -> [GrantEntitlementRequest]
entitlements} -> [GrantEntitlementRequest]
entitlements) (\s :: GrantFlowEntitlements
s@GrantFlowEntitlements' {} [GrantEntitlementRequest]
a -> GrantFlowEntitlements
s {$sel:entitlements:GrantFlowEntitlements' :: [GrantEntitlementRequest]
entitlements = [GrantEntitlementRequest]
a} :: GrantFlowEntitlements) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest GrantFlowEntitlements where
  type
    AWSResponse GrantFlowEntitlements =
      GrantFlowEntitlementsResponse
  request :: (Service -> Service)
-> GrantFlowEntitlements -> Request GrantFlowEntitlements
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 GrantFlowEntitlements
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GrantFlowEntitlements)))
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 [Entitlement]
-> Maybe Text -> Int -> GrantFlowEntitlementsResponse
GrantFlowEntitlementsResponse'
            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
"entitlements" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"flowArn")
            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 GrantFlowEntitlements where
  hashWithSalt :: Int -> GrantFlowEntitlements -> Int
hashWithSalt Int
_salt GrantFlowEntitlements' {[GrantEntitlementRequest]
Text
entitlements :: [GrantEntitlementRequest]
flowArn :: Text
$sel:entitlements:GrantFlowEntitlements' :: GrantFlowEntitlements -> [GrantEntitlementRequest]
$sel:flowArn:GrantFlowEntitlements' :: GrantFlowEntitlements -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
flowArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [GrantEntitlementRequest]
entitlements

instance Prelude.NFData GrantFlowEntitlements where
  rnf :: GrantFlowEntitlements -> ()
rnf GrantFlowEntitlements' {[GrantEntitlementRequest]
Text
entitlements :: [GrantEntitlementRequest]
flowArn :: Text
$sel:entitlements:GrantFlowEntitlements' :: GrantFlowEntitlements -> [GrantEntitlementRequest]
$sel:flowArn:GrantFlowEntitlements' :: GrantFlowEntitlements -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
flowArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [GrantEntitlementRequest]
entitlements

instance Data.ToHeaders GrantFlowEntitlements where
  toHeaders :: GrantFlowEntitlements -> 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 GrantFlowEntitlements where
  toJSON :: GrantFlowEntitlements -> Value
toJSON GrantFlowEntitlements' {[GrantEntitlementRequest]
Text
entitlements :: [GrantEntitlementRequest]
flowArn :: Text
$sel:entitlements:GrantFlowEntitlements' :: GrantFlowEntitlements -> [GrantEntitlementRequest]
$sel:flowArn:GrantFlowEntitlements' :: GrantFlowEntitlements -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"entitlements" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [GrantEntitlementRequest]
entitlements)]
      )

instance Data.ToPath GrantFlowEntitlements where
  toPath :: GrantFlowEntitlements -> ByteString
toPath GrantFlowEntitlements' {[GrantEntitlementRequest]
Text
entitlements :: [GrantEntitlementRequest]
flowArn :: Text
$sel:entitlements:GrantFlowEntitlements' :: GrantFlowEntitlements -> [GrantEntitlementRequest]
$sel:flowArn:GrantFlowEntitlements' :: GrantFlowEntitlements -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v1/flows/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
flowArn, ByteString
"/entitlements"]

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

-- | /See:/ 'newGrantFlowEntitlementsResponse' smart constructor.
data GrantFlowEntitlementsResponse = GrantFlowEntitlementsResponse'
  { -- | The entitlements that were just granted.
    GrantFlowEntitlementsResponse -> Maybe [Entitlement]
entitlements :: Prelude.Maybe [Entitlement],
    -- | The ARN of the flow that these entitlements were granted to.
    GrantFlowEntitlementsResponse -> Maybe Text
flowArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GrantFlowEntitlementsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GrantFlowEntitlementsResponse
-> GrantFlowEntitlementsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GrantFlowEntitlementsResponse
-> GrantFlowEntitlementsResponse -> Bool
$c/= :: GrantFlowEntitlementsResponse
-> GrantFlowEntitlementsResponse -> Bool
== :: GrantFlowEntitlementsResponse
-> GrantFlowEntitlementsResponse -> Bool
$c== :: GrantFlowEntitlementsResponse
-> GrantFlowEntitlementsResponse -> Bool
Prelude.Eq, ReadPrec [GrantFlowEntitlementsResponse]
ReadPrec GrantFlowEntitlementsResponse
Int -> ReadS GrantFlowEntitlementsResponse
ReadS [GrantFlowEntitlementsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GrantFlowEntitlementsResponse]
$creadListPrec :: ReadPrec [GrantFlowEntitlementsResponse]
readPrec :: ReadPrec GrantFlowEntitlementsResponse
$creadPrec :: ReadPrec GrantFlowEntitlementsResponse
readList :: ReadS [GrantFlowEntitlementsResponse]
$creadList :: ReadS [GrantFlowEntitlementsResponse]
readsPrec :: Int -> ReadS GrantFlowEntitlementsResponse
$creadsPrec :: Int -> ReadS GrantFlowEntitlementsResponse
Prelude.Read, Int -> GrantFlowEntitlementsResponse -> ShowS
[GrantFlowEntitlementsResponse] -> ShowS
GrantFlowEntitlementsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GrantFlowEntitlementsResponse] -> ShowS
$cshowList :: [GrantFlowEntitlementsResponse] -> ShowS
show :: GrantFlowEntitlementsResponse -> String
$cshow :: GrantFlowEntitlementsResponse -> String
showsPrec :: Int -> GrantFlowEntitlementsResponse -> ShowS
$cshowsPrec :: Int -> GrantFlowEntitlementsResponse -> ShowS
Prelude.Show, forall x.
Rep GrantFlowEntitlementsResponse x
-> GrantFlowEntitlementsResponse
forall x.
GrantFlowEntitlementsResponse
-> Rep GrantFlowEntitlementsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GrantFlowEntitlementsResponse x
-> GrantFlowEntitlementsResponse
$cfrom :: forall x.
GrantFlowEntitlementsResponse
-> Rep GrantFlowEntitlementsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GrantFlowEntitlementsResponse' 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:
--
-- 'entitlements', 'grantFlowEntitlementsResponse_entitlements' - The entitlements that were just granted.
--
-- 'flowArn', 'grantFlowEntitlementsResponse_flowArn' - The ARN of the flow that these entitlements were granted to.
--
-- 'httpStatus', 'grantFlowEntitlementsResponse_httpStatus' - The response's http status code.
newGrantFlowEntitlementsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GrantFlowEntitlementsResponse
newGrantFlowEntitlementsResponse :: Int -> GrantFlowEntitlementsResponse
newGrantFlowEntitlementsResponse Int
pHttpStatus_ =
  GrantFlowEntitlementsResponse'
    { $sel:entitlements:GrantFlowEntitlementsResponse' :: Maybe [Entitlement]
entitlements =
        forall a. Maybe a
Prelude.Nothing,
      $sel:flowArn:GrantFlowEntitlementsResponse' :: Maybe Text
flowArn = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GrantFlowEntitlementsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The entitlements that were just granted.
grantFlowEntitlementsResponse_entitlements :: Lens.Lens' GrantFlowEntitlementsResponse (Prelude.Maybe [Entitlement])
grantFlowEntitlementsResponse_entitlements :: Lens' GrantFlowEntitlementsResponse (Maybe [Entitlement])
grantFlowEntitlementsResponse_entitlements = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrantFlowEntitlementsResponse' {Maybe [Entitlement]
entitlements :: Maybe [Entitlement]
$sel:entitlements:GrantFlowEntitlementsResponse' :: GrantFlowEntitlementsResponse -> Maybe [Entitlement]
entitlements} -> Maybe [Entitlement]
entitlements) (\s :: GrantFlowEntitlementsResponse
s@GrantFlowEntitlementsResponse' {} Maybe [Entitlement]
a -> GrantFlowEntitlementsResponse
s {$sel:entitlements:GrantFlowEntitlementsResponse' :: Maybe [Entitlement]
entitlements = Maybe [Entitlement]
a} :: GrantFlowEntitlementsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ARN of the flow that these entitlements were granted to.
grantFlowEntitlementsResponse_flowArn :: Lens.Lens' GrantFlowEntitlementsResponse (Prelude.Maybe Prelude.Text)
grantFlowEntitlementsResponse_flowArn :: Lens' GrantFlowEntitlementsResponse (Maybe Text)
grantFlowEntitlementsResponse_flowArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrantFlowEntitlementsResponse' {Maybe Text
flowArn :: Maybe Text
$sel:flowArn:GrantFlowEntitlementsResponse' :: GrantFlowEntitlementsResponse -> Maybe Text
flowArn} -> Maybe Text
flowArn) (\s :: GrantFlowEntitlementsResponse
s@GrantFlowEntitlementsResponse' {} Maybe Text
a -> GrantFlowEntitlementsResponse
s {$sel:flowArn:GrantFlowEntitlementsResponse' :: Maybe Text
flowArn = Maybe Text
a} :: GrantFlowEntitlementsResponse)

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

instance Prelude.NFData GrantFlowEntitlementsResponse where
  rnf :: GrantFlowEntitlementsResponse -> ()
rnf GrantFlowEntitlementsResponse' {Int
Maybe [Entitlement]
Maybe Text
httpStatus :: Int
flowArn :: Maybe Text
entitlements :: Maybe [Entitlement]
$sel:httpStatus:GrantFlowEntitlementsResponse' :: GrantFlowEntitlementsResponse -> Int
$sel:flowArn:GrantFlowEntitlementsResponse' :: GrantFlowEntitlementsResponse -> Maybe Text
$sel:entitlements:GrantFlowEntitlementsResponse' :: GrantFlowEntitlementsResponse -> Maybe [Entitlement]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Entitlement]
entitlements
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
flowArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus