{-# 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.WorkDocs.CreateCustomMetadata
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Adds one or more custom properties to the specified resource (a folder,
-- document, or version).
module Amazonka.WorkDocs.CreateCustomMetadata
  ( -- * Creating a Request
    CreateCustomMetadata (..),
    newCreateCustomMetadata,

    -- * Request Lenses
    createCustomMetadata_authenticationToken,
    createCustomMetadata_versionId,
    createCustomMetadata_resourceId,
    createCustomMetadata_customMetadata,

    -- * Destructuring the Response
    CreateCustomMetadataResponse (..),
    newCreateCustomMetadataResponse,

    -- * Response Lenses
    createCustomMetadataResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateCustomMetadata' smart constructor.
data CreateCustomMetadata = CreateCustomMetadata'
  { -- | Amazon WorkDocs authentication token. Not required when using AWS
    -- administrator credentials to access the API.
    CreateCustomMetadata -> Maybe (Sensitive Text)
authenticationToken :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | The ID of the version, if the custom metadata is being added to a
    -- document version.
    CreateCustomMetadata -> Maybe Text
versionId :: Prelude.Maybe Prelude.Text,
    -- | The ID of the resource.
    CreateCustomMetadata -> Text
resourceId :: Prelude.Text,
    -- | Custom metadata in the form of name-value pairs.
    CreateCustomMetadata -> HashMap Text Text
customMetadata :: Prelude.HashMap Prelude.Text Prelude.Text
  }
  deriving (CreateCustomMetadata -> CreateCustomMetadata -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateCustomMetadata -> CreateCustomMetadata -> Bool
$c/= :: CreateCustomMetadata -> CreateCustomMetadata -> Bool
== :: CreateCustomMetadata -> CreateCustomMetadata -> Bool
$c== :: CreateCustomMetadata -> CreateCustomMetadata -> Bool
Prelude.Eq, Int -> CreateCustomMetadata -> ShowS
[CreateCustomMetadata] -> ShowS
CreateCustomMetadata -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateCustomMetadata] -> ShowS
$cshowList :: [CreateCustomMetadata] -> ShowS
show :: CreateCustomMetadata -> String
$cshow :: CreateCustomMetadata -> String
showsPrec :: Int -> CreateCustomMetadata -> ShowS
$cshowsPrec :: Int -> CreateCustomMetadata -> ShowS
Prelude.Show, forall x. Rep CreateCustomMetadata x -> CreateCustomMetadata
forall x. CreateCustomMetadata -> Rep CreateCustomMetadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateCustomMetadata x -> CreateCustomMetadata
$cfrom :: forall x. CreateCustomMetadata -> Rep CreateCustomMetadata x
Prelude.Generic)

-- |
-- Create a value of 'CreateCustomMetadata' 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:
--
-- 'authenticationToken', 'createCustomMetadata_authenticationToken' - Amazon WorkDocs authentication token. Not required when using AWS
-- administrator credentials to access the API.
--
-- 'versionId', 'createCustomMetadata_versionId' - The ID of the version, if the custom metadata is being added to a
-- document version.
--
-- 'resourceId', 'createCustomMetadata_resourceId' - The ID of the resource.
--
-- 'customMetadata', 'createCustomMetadata_customMetadata' - Custom metadata in the form of name-value pairs.
newCreateCustomMetadata ::
  -- | 'resourceId'
  Prelude.Text ->
  CreateCustomMetadata
newCreateCustomMetadata :: Text -> CreateCustomMetadata
newCreateCustomMetadata Text
pResourceId_ =
  CreateCustomMetadata'
    { $sel:authenticationToken:CreateCustomMetadata' :: Maybe (Sensitive Text)
authenticationToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:versionId:CreateCustomMetadata' :: Maybe Text
versionId = forall a. Maybe a
Prelude.Nothing,
      $sel:resourceId:CreateCustomMetadata' :: Text
resourceId = Text
pResourceId_,
      $sel:customMetadata:CreateCustomMetadata' :: HashMap Text Text
customMetadata = forall a. Monoid a => a
Prelude.mempty
    }

-- | Amazon WorkDocs authentication token. Not required when using AWS
-- administrator credentials to access the API.
createCustomMetadata_authenticationToken :: Lens.Lens' CreateCustomMetadata (Prelude.Maybe Prelude.Text)
createCustomMetadata_authenticationToken :: Lens' CreateCustomMetadata (Maybe Text)
createCustomMetadata_authenticationToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCustomMetadata' {Maybe (Sensitive Text)
authenticationToken :: Maybe (Sensitive Text)
$sel:authenticationToken:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe (Sensitive Text)
authenticationToken} -> Maybe (Sensitive Text)
authenticationToken) (\s :: CreateCustomMetadata
s@CreateCustomMetadata' {} Maybe (Sensitive Text)
a -> CreateCustomMetadata
s {$sel:authenticationToken:CreateCustomMetadata' :: Maybe (Sensitive Text)
authenticationToken = Maybe (Sensitive Text)
a} :: CreateCustomMetadata) 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 a. Iso' (Sensitive a) a
Data._Sensitive

-- | The ID of the version, if the custom metadata is being added to a
-- document version.
createCustomMetadata_versionId :: Lens.Lens' CreateCustomMetadata (Prelude.Maybe Prelude.Text)
createCustomMetadata_versionId :: Lens' CreateCustomMetadata (Maybe Text)
createCustomMetadata_versionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCustomMetadata' {Maybe Text
versionId :: Maybe Text
$sel:versionId:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe Text
versionId} -> Maybe Text
versionId) (\s :: CreateCustomMetadata
s@CreateCustomMetadata' {} Maybe Text
a -> CreateCustomMetadata
s {$sel:versionId:CreateCustomMetadata' :: Maybe Text
versionId = Maybe Text
a} :: CreateCustomMetadata)

-- | The ID of the resource.
createCustomMetadata_resourceId :: Lens.Lens' CreateCustomMetadata Prelude.Text
createCustomMetadata_resourceId :: Lens' CreateCustomMetadata Text
createCustomMetadata_resourceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCustomMetadata' {Text
resourceId :: Text
$sel:resourceId:CreateCustomMetadata' :: CreateCustomMetadata -> Text
resourceId} -> Text
resourceId) (\s :: CreateCustomMetadata
s@CreateCustomMetadata' {} Text
a -> CreateCustomMetadata
s {$sel:resourceId:CreateCustomMetadata' :: Text
resourceId = Text
a} :: CreateCustomMetadata)

-- | Custom metadata in the form of name-value pairs.
createCustomMetadata_customMetadata :: Lens.Lens' CreateCustomMetadata (Prelude.HashMap Prelude.Text Prelude.Text)
createCustomMetadata_customMetadata :: Lens' CreateCustomMetadata (HashMap Text Text)
createCustomMetadata_customMetadata = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCustomMetadata' {HashMap Text Text
customMetadata :: HashMap Text Text
$sel:customMetadata:CreateCustomMetadata' :: CreateCustomMetadata -> HashMap Text Text
customMetadata} -> HashMap Text Text
customMetadata) (\s :: CreateCustomMetadata
s@CreateCustomMetadata' {} HashMap Text Text
a -> CreateCustomMetadata
s {$sel:customMetadata:CreateCustomMetadata' :: HashMap Text Text
customMetadata = HashMap Text Text
a} :: CreateCustomMetadata) 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 CreateCustomMetadata where
  type
    AWSResponse CreateCustomMetadata =
      CreateCustomMetadataResponse
  request :: (Service -> Service)
-> CreateCustomMetadata -> Request CreateCustomMetadata
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CreateCustomMetadata
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateCustomMetadata)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> CreateCustomMetadataResponse
CreateCustomMetadataResponse'
            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))
      )

instance Prelude.Hashable CreateCustomMetadata where
  hashWithSalt :: Int -> CreateCustomMetadata -> Int
hashWithSalt Int
_salt CreateCustomMetadata' {Maybe Text
Maybe (Sensitive Text)
Text
HashMap Text Text
customMetadata :: HashMap Text Text
resourceId :: Text
versionId :: Maybe Text
authenticationToken :: Maybe (Sensitive Text)
$sel:customMetadata:CreateCustomMetadata' :: CreateCustomMetadata -> HashMap Text Text
$sel:resourceId:CreateCustomMetadata' :: CreateCustomMetadata -> Text
$sel:versionId:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe Text
$sel:authenticationToken:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe (Sensitive Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
authenticationToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
versionId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resourceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` HashMap Text Text
customMetadata

instance Prelude.NFData CreateCustomMetadata where
  rnf :: CreateCustomMetadata -> ()
rnf CreateCustomMetadata' {Maybe Text
Maybe (Sensitive Text)
Text
HashMap Text Text
customMetadata :: HashMap Text Text
resourceId :: Text
versionId :: Maybe Text
authenticationToken :: Maybe (Sensitive Text)
$sel:customMetadata:CreateCustomMetadata' :: CreateCustomMetadata -> HashMap Text Text
$sel:resourceId:CreateCustomMetadata' :: CreateCustomMetadata -> Text
$sel:versionId:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe Text
$sel:authenticationToken:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe (Sensitive Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
authenticationToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
versionId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
resourceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf HashMap Text Text
customMetadata

instance Data.ToHeaders CreateCustomMetadata where
  toHeaders :: CreateCustomMetadata -> ResponseHeaders
toHeaders CreateCustomMetadata' {Maybe Text
Maybe (Sensitive Text)
Text
HashMap Text Text
customMetadata :: HashMap Text Text
resourceId :: Text
versionId :: Maybe Text
authenticationToken :: Maybe (Sensitive Text)
$sel:customMetadata:CreateCustomMetadata' :: CreateCustomMetadata -> HashMap Text Text
$sel:resourceId:CreateCustomMetadata' :: CreateCustomMetadata -> Text
$sel:versionId:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe Text
$sel:authenticationToken:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe (Sensitive Text)
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"Authentication" forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# Maybe (Sensitive Text)
authenticationToken,
        HeaderName
"Content-Type"
          forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# (ByteString
"application/x-amz-json-1.1" :: Prelude.ByteString)
      ]

instance Data.ToJSON CreateCustomMetadata where
  toJSON :: CreateCustomMetadata -> Value
toJSON CreateCustomMetadata' {Maybe Text
Maybe (Sensitive Text)
Text
HashMap Text Text
customMetadata :: HashMap Text Text
resourceId :: Text
versionId :: Maybe Text
authenticationToken :: Maybe (Sensitive Text)
$sel:customMetadata:CreateCustomMetadata' :: CreateCustomMetadata -> HashMap Text Text
$sel:resourceId:CreateCustomMetadata' :: CreateCustomMetadata -> Text
$sel:versionId:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe Text
$sel:authenticationToken:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe (Sensitive Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"CustomMetadata" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= HashMap Text Text
customMetadata)
          ]
      )

instance Data.ToPath CreateCustomMetadata where
  toPath :: CreateCustomMetadata -> ByteString
toPath CreateCustomMetadata' {Maybe Text
Maybe (Sensitive Text)
Text
HashMap Text Text
customMetadata :: HashMap Text Text
resourceId :: Text
versionId :: Maybe Text
authenticationToken :: Maybe (Sensitive Text)
$sel:customMetadata:CreateCustomMetadata' :: CreateCustomMetadata -> HashMap Text Text
$sel:resourceId:CreateCustomMetadata' :: CreateCustomMetadata -> Text
$sel:versionId:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe Text
$sel:authenticationToken:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe (Sensitive Text)
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/api/v1/resources/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
resourceId,
        ByteString
"/customMetadata"
      ]

instance Data.ToQuery CreateCustomMetadata where
  toQuery :: CreateCustomMetadata -> QueryString
toQuery CreateCustomMetadata' {Maybe Text
Maybe (Sensitive Text)
Text
HashMap Text Text
customMetadata :: HashMap Text Text
resourceId :: Text
versionId :: Maybe Text
authenticationToken :: Maybe (Sensitive Text)
$sel:customMetadata:CreateCustomMetadata' :: CreateCustomMetadata -> HashMap Text Text
$sel:resourceId:CreateCustomMetadata' :: CreateCustomMetadata -> Text
$sel:versionId:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe Text
$sel:authenticationToken:CreateCustomMetadata' :: CreateCustomMetadata -> Maybe (Sensitive Text)
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"versionid" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
versionId]

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

-- |
-- Create a value of 'CreateCustomMetadataResponse' 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', 'createCustomMetadataResponse_httpStatus' - The response's http status code.
newCreateCustomMetadataResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateCustomMetadataResponse
newCreateCustomMetadataResponse :: Int -> CreateCustomMetadataResponse
newCreateCustomMetadataResponse Int
pHttpStatus_ =
  CreateCustomMetadataResponse'
    { $sel:httpStatus:CreateCustomMetadataResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData CreateCustomMetadataResponse where
  rnf :: CreateCustomMetadataResponse -> ()
rnf CreateCustomMetadataResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateCustomMetadataResponse' :: CreateCustomMetadataResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus