{-# 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.Grafana.UpdatePermissions
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates which users in a workspace have the Grafana @Admin@ or @Editor@
-- roles.
module Amazonka.Grafana.UpdatePermissions
  ( -- * Creating a Request
    UpdatePermissions (..),
    newUpdatePermissions,

    -- * Request Lenses
    updatePermissions_updateInstructionBatch,
    updatePermissions_workspaceId,

    -- * Destructuring the Response
    UpdatePermissionsResponse (..),
    newUpdatePermissionsResponse,

    -- * Response Lenses
    updatePermissionsResponse_httpStatus,
    updatePermissionsResponse_errors,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Grafana.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newUpdatePermissions' smart constructor.
data UpdatePermissions = UpdatePermissions'
  { -- | An array of structures that contain the permission updates to make.
    UpdatePermissions -> [UpdateInstruction]
updateInstructionBatch :: [UpdateInstruction],
    -- | The ID of the workspace to update.
    UpdatePermissions -> Text
workspaceId :: Prelude.Text
  }
  deriving (UpdatePermissions -> UpdatePermissions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdatePermissions -> UpdatePermissions -> Bool
$c/= :: UpdatePermissions -> UpdatePermissions -> Bool
== :: UpdatePermissions -> UpdatePermissions -> Bool
$c== :: UpdatePermissions -> UpdatePermissions -> Bool
Prelude.Eq, ReadPrec [UpdatePermissions]
ReadPrec UpdatePermissions
Int -> ReadS UpdatePermissions
ReadS [UpdatePermissions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdatePermissions]
$creadListPrec :: ReadPrec [UpdatePermissions]
readPrec :: ReadPrec UpdatePermissions
$creadPrec :: ReadPrec UpdatePermissions
readList :: ReadS [UpdatePermissions]
$creadList :: ReadS [UpdatePermissions]
readsPrec :: Int -> ReadS UpdatePermissions
$creadsPrec :: Int -> ReadS UpdatePermissions
Prelude.Read, Int -> UpdatePermissions -> ShowS
[UpdatePermissions] -> ShowS
UpdatePermissions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdatePermissions] -> ShowS
$cshowList :: [UpdatePermissions] -> ShowS
show :: UpdatePermissions -> String
$cshow :: UpdatePermissions -> String
showsPrec :: Int -> UpdatePermissions -> ShowS
$cshowsPrec :: Int -> UpdatePermissions -> ShowS
Prelude.Show, forall x. Rep UpdatePermissions x -> UpdatePermissions
forall x. UpdatePermissions -> Rep UpdatePermissions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdatePermissions x -> UpdatePermissions
$cfrom :: forall x. UpdatePermissions -> Rep UpdatePermissions x
Prelude.Generic)

-- |
-- Create a value of 'UpdatePermissions' 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:
--
-- 'updateInstructionBatch', 'updatePermissions_updateInstructionBatch' - An array of structures that contain the permission updates to make.
--
-- 'workspaceId', 'updatePermissions_workspaceId' - The ID of the workspace to update.
newUpdatePermissions ::
  -- | 'workspaceId'
  Prelude.Text ->
  UpdatePermissions
newUpdatePermissions :: Text -> UpdatePermissions
newUpdatePermissions Text
pWorkspaceId_ =
  UpdatePermissions'
    { $sel:updateInstructionBatch:UpdatePermissions' :: [UpdateInstruction]
updateInstructionBatch =
        forall a. Monoid a => a
Prelude.mempty,
      $sel:workspaceId:UpdatePermissions' :: Text
workspaceId = Text
pWorkspaceId_
    }

-- | An array of structures that contain the permission updates to make.
updatePermissions_updateInstructionBatch :: Lens.Lens' UpdatePermissions [UpdateInstruction]
updatePermissions_updateInstructionBatch :: Lens' UpdatePermissions [UpdateInstruction]
updatePermissions_updateInstructionBatch = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePermissions' {[UpdateInstruction]
updateInstructionBatch :: [UpdateInstruction]
$sel:updateInstructionBatch:UpdatePermissions' :: UpdatePermissions -> [UpdateInstruction]
updateInstructionBatch} -> [UpdateInstruction]
updateInstructionBatch) (\s :: UpdatePermissions
s@UpdatePermissions' {} [UpdateInstruction]
a -> UpdatePermissions
s {$sel:updateInstructionBatch:UpdatePermissions' :: [UpdateInstruction]
updateInstructionBatch = [UpdateInstruction]
a} :: UpdatePermissions) 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

-- | The ID of the workspace to update.
updatePermissions_workspaceId :: Lens.Lens' UpdatePermissions Prelude.Text
updatePermissions_workspaceId :: Lens' UpdatePermissions Text
updatePermissions_workspaceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePermissions' {Text
workspaceId :: Text
$sel:workspaceId:UpdatePermissions' :: UpdatePermissions -> Text
workspaceId} -> Text
workspaceId) (\s :: UpdatePermissions
s@UpdatePermissions' {} Text
a -> UpdatePermissions
s {$sel:workspaceId:UpdatePermissions' :: Text
workspaceId = Text
a} :: UpdatePermissions)

instance Core.AWSRequest UpdatePermissions where
  type
    AWSResponse UpdatePermissions =
      UpdatePermissionsResponse
  request :: (Service -> Service)
-> UpdatePermissions -> Request UpdatePermissions
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.patchJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy UpdatePermissions
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdatePermissions)))
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 ->
          Int -> [UpdateError] -> UpdatePermissionsResponse
UpdatePermissionsResponse'
            forall (f :: * -> *) a b. Functor 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))
            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
"errors" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable UpdatePermissions where
  hashWithSalt :: Int -> UpdatePermissions -> Int
hashWithSalt Int
_salt UpdatePermissions' {[UpdateInstruction]
Text
workspaceId :: Text
updateInstructionBatch :: [UpdateInstruction]
$sel:workspaceId:UpdatePermissions' :: UpdatePermissions -> Text
$sel:updateInstructionBatch:UpdatePermissions' :: UpdatePermissions -> [UpdateInstruction]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [UpdateInstruction]
updateInstructionBatch
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
workspaceId

instance Prelude.NFData UpdatePermissions where
  rnf :: UpdatePermissions -> ()
rnf UpdatePermissions' {[UpdateInstruction]
Text
workspaceId :: Text
updateInstructionBatch :: [UpdateInstruction]
$sel:workspaceId:UpdatePermissions' :: UpdatePermissions -> Text
$sel:updateInstructionBatch:UpdatePermissions' :: UpdatePermissions -> [UpdateInstruction]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf [UpdateInstruction]
updateInstructionBatch
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
workspaceId

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

instance Data.ToPath UpdatePermissions where
  toPath :: UpdatePermissions -> ByteString
toPath UpdatePermissions' {[UpdateInstruction]
Text
workspaceId :: Text
updateInstructionBatch :: [UpdateInstruction]
$sel:workspaceId:UpdatePermissions' :: UpdatePermissions -> Text
$sel:updateInstructionBatch:UpdatePermissions' :: UpdatePermissions -> [UpdateInstruction]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/workspaces/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
workspaceId,
        ByteString
"/permissions"
      ]

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

-- | /See:/ 'newUpdatePermissionsResponse' smart constructor.
data UpdatePermissionsResponse = UpdatePermissionsResponse'
  { -- | The response's http status code.
    UpdatePermissionsResponse -> Int
httpStatus :: Prelude.Int,
    -- | An array of structures that contain the errors from the operation, if
    -- any.
    UpdatePermissionsResponse -> [UpdateError]
errors :: [UpdateError]
  }
  deriving (UpdatePermissionsResponse -> UpdatePermissionsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdatePermissionsResponse -> UpdatePermissionsResponse -> Bool
$c/= :: UpdatePermissionsResponse -> UpdatePermissionsResponse -> Bool
== :: UpdatePermissionsResponse -> UpdatePermissionsResponse -> Bool
$c== :: UpdatePermissionsResponse -> UpdatePermissionsResponse -> Bool
Prelude.Eq, ReadPrec [UpdatePermissionsResponse]
ReadPrec UpdatePermissionsResponse
Int -> ReadS UpdatePermissionsResponse
ReadS [UpdatePermissionsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdatePermissionsResponse]
$creadListPrec :: ReadPrec [UpdatePermissionsResponse]
readPrec :: ReadPrec UpdatePermissionsResponse
$creadPrec :: ReadPrec UpdatePermissionsResponse
readList :: ReadS [UpdatePermissionsResponse]
$creadList :: ReadS [UpdatePermissionsResponse]
readsPrec :: Int -> ReadS UpdatePermissionsResponse
$creadsPrec :: Int -> ReadS UpdatePermissionsResponse
Prelude.Read, Int -> UpdatePermissionsResponse -> ShowS
[UpdatePermissionsResponse] -> ShowS
UpdatePermissionsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdatePermissionsResponse] -> ShowS
$cshowList :: [UpdatePermissionsResponse] -> ShowS
show :: UpdatePermissionsResponse -> String
$cshow :: UpdatePermissionsResponse -> String
showsPrec :: Int -> UpdatePermissionsResponse -> ShowS
$cshowsPrec :: Int -> UpdatePermissionsResponse -> ShowS
Prelude.Show, forall x.
Rep UpdatePermissionsResponse x -> UpdatePermissionsResponse
forall x.
UpdatePermissionsResponse -> Rep UpdatePermissionsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdatePermissionsResponse x -> UpdatePermissionsResponse
$cfrom :: forall x.
UpdatePermissionsResponse -> Rep UpdatePermissionsResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdatePermissionsResponse' 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', 'updatePermissionsResponse_httpStatus' - The response's http status code.
--
-- 'errors', 'updatePermissionsResponse_errors' - An array of structures that contain the errors from the operation, if
-- any.
newUpdatePermissionsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdatePermissionsResponse
newUpdatePermissionsResponse :: Int -> UpdatePermissionsResponse
newUpdatePermissionsResponse Int
pHttpStatus_ =
  UpdatePermissionsResponse'
    { $sel:httpStatus:UpdatePermissionsResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:errors:UpdatePermissionsResponse' :: [UpdateError]
errors = forall a. Monoid a => a
Prelude.mempty
    }

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

-- | An array of structures that contain the errors from the operation, if
-- any.
updatePermissionsResponse_errors :: Lens.Lens' UpdatePermissionsResponse [UpdateError]
updatePermissionsResponse_errors :: Lens' UpdatePermissionsResponse [UpdateError]
updatePermissionsResponse_errors = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePermissionsResponse' {[UpdateError]
errors :: [UpdateError]
$sel:errors:UpdatePermissionsResponse' :: UpdatePermissionsResponse -> [UpdateError]
errors} -> [UpdateError]
errors) (\s :: UpdatePermissionsResponse
s@UpdatePermissionsResponse' {} [UpdateError]
a -> UpdatePermissionsResponse
s {$sel:errors:UpdatePermissionsResponse' :: [UpdateError]
errors = [UpdateError]
a} :: UpdatePermissionsResponse) 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 Prelude.NFData UpdatePermissionsResponse where
  rnf :: UpdatePermissionsResponse -> ()
rnf UpdatePermissionsResponse' {Int
[UpdateError]
errors :: [UpdateError]
httpStatus :: Int
$sel:errors:UpdatePermissionsResponse' :: UpdatePermissionsResponse -> [UpdateError]
$sel:httpStatus:UpdatePermissionsResponse' :: UpdatePermissionsResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [UpdateError]
errors