{-# 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.CloudDirectory.UpdateFacet
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Does the following:
--
-- 1.  Adds new @Attributes@, @Rules@, or @ObjectTypes@.
--
-- 2.  Updates existing @Attributes@, @Rules@, or @ObjectTypes@.
--
-- 3.  Deletes existing @Attributes@, @Rules@, or @ObjectTypes@.
module Amazonka.CloudDirectory.UpdateFacet
  ( -- * Creating a Request
    UpdateFacet (..),
    newUpdateFacet,

    -- * Request Lenses
    updateFacet_attributeUpdates,
    updateFacet_objectType,
    updateFacet_schemaArn,
    updateFacet_name,

    -- * Destructuring the Response
    UpdateFacetResponse (..),
    newUpdateFacetResponse,

    -- * Response Lenses
    updateFacetResponse_httpStatus,
  )
where

import Amazonka.CloudDirectory.Types
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

-- | /See:/ 'newUpdateFacet' smart constructor.
data UpdateFacet = UpdateFacet'
  { -- | List of attributes that need to be updated in a given schema Facet. Each
    -- attribute is followed by @AttributeAction@, which specifies the type of
    -- update operation to perform.
    UpdateFacet -> Maybe [FacetAttributeUpdate]
attributeUpdates :: Prelude.Maybe [FacetAttributeUpdate],
    -- | The object type that is associated with the facet. See
    -- CreateFacetRequest$ObjectType for more details.
    UpdateFacet -> Maybe ObjectType
objectType :: Prelude.Maybe ObjectType,
    -- | The Amazon Resource Name (ARN) that is associated with the Facet. For
    -- more information, see arns.
    UpdateFacet -> Text
schemaArn :: Prelude.Text,
    -- | The name of the facet.
    UpdateFacet -> Text
name :: Prelude.Text
  }
  deriving (UpdateFacet -> UpdateFacet -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateFacet -> UpdateFacet -> Bool
$c/= :: UpdateFacet -> UpdateFacet -> Bool
== :: UpdateFacet -> UpdateFacet -> Bool
$c== :: UpdateFacet -> UpdateFacet -> Bool
Prelude.Eq, ReadPrec [UpdateFacet]
ReadPrec UpdateFacet
Int -> ReadS UpdateFacet
ReadS [UpdateFacet]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateFacet]
$creadListPrec :: ReadPrec [UpdateFacet]
readPrec :: ReadPrec UpdateFacet
$creadPrec :: ReadPrec UpdateFacet
readList :: ReadS [UpdateFacet]
$creadList :: ReadS [UpdateFacet]
readsPrec :: Int -> ReadS UpdateFacet
$creadsPrec :: Int -> ReadS UpdateFacet
Prelude.Read, Int -> UpdateFacet -> ShowS
[UpdateFacet] -> ShowS
UpdateFacet -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateFacet] -> ShowS
$cshowList :: [UpdateFacet] -> ShowS
show :: UpdateFacet -> String
$cshow :: UpdateFacet -> String
showsPrec :: Int -> UpdateFacet -> ShowS
$cshowsPrec :: Int -> UpdateFacet -> ShowS
Prelude.Show, forall x. Rep UpdateFacet x -> UpdateFacet
forall x. UpdateFacet -> Rep UpdateFacet x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateFacet x -> UpdateFacet
$cfrom :: forall x. UpdateFacet -> Rep UpdateFacet x
Prelude.Generic)

-- |
-- Create a value of 'UpdateFacet' 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:
--
-- 'attributeUpdates', 'updateFacet_attributeUpdates' - List of attributes that need to be updated in a given schema Facet. Each
-- attribute is followed by @AttributeAction@, which specifies the type of
-- update operation to perform.
--
-- 'objectType', 'updateFacet_objectType' - The object type that is associated with the facet. See
-- CreateFacetRequest$ObjectType for more details.
--
-- 'schemaArn', 'updateFacet_schemaArn' - The Amazon Resource Name (ARN) that is associated with the Facet. For
-- more information, see arns.
--
-- 'name', 'updateFacet_name' - The name of the facet.
newUpdateFacet ::
  -- | 'schemaArn'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  UpdateFacet
newUpdateFacet :: Text -> Text -> UpdateFacet
newUpdateFacet Text
pSchemaArn_ Text
pName_ =
  UpdateFacet'
    { $sel:attributeUpdates:UpdateFacet' :: Maybe [FacetAttributeUpdate]
attributeUpdates = forall a. Maybe a
Prelude.Nothing,
      $sel:objectType:UpdateFacet' :: Maybe ObjectType
objectType = forall a. Maybe a
Prelude.Nothing,
      $sel:schemaArn:UpdateFacet' :: Text
schemaArn = Text
pSchemaArn_,
      $sel:name:UpdateFacet' :: Text
name = Text
pName_
    }

-- | List of attributes that need to be updated in a given schema Facet. Each
-- attribute is followed by @AttributeAction@, which specifies the type of
-- update operation to perform.
updateFacet_attributeUpdates :: Lens.Lens' UpdateFacet (Prelude.Maybe [FacetAttributeUpdate])
updateFacet_attributeUpdates :: Lens' UpdateFacet (Maybe [FacetAttributeUpdate])
updateFacet_attributeUpdates = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateFacet' {Maybe [FacetAttributeUpdate]
attributeUpdates :: Maybe [FacetAttributeUpdate]
$sel:attributeUpdates:UpdateFacet' :: UpdateFacet -> Maybe [FacetAttributeUpdate]
attributeUpdates} -> Maybe [FacetAttributeUpdate]
attributeUpdates) (\s :: UpdateFacet
s@UpdateFacet' {} Maybe [FacetAttributeUpdate]
a -> UpdateFacet
s {$sel:attributeUpdates:UpdateFacet' :: Maybe [FacetAttributeUpdate]
attributeUpdates = Maybe [FacetAttributeUpdate]
a} :: UpdateFacet) 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 object type that is associated with the facet. See
-- CreateFacetRequest$ObjectType for more details.
updateFacet_objectType :: Lens.Lens' UpdateFacet (Prelude.Maybe ObjectType)
updateFacet_objectType :: Lens' UpdateFacet (Maybe ObjectType)
updateFacet_objectType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateFacet' {Maybe ObjectType
objectType :: Maybe ObjectType
$sel:objectType:UpdateFacet' :: UpdateFacet -> Maybe ObjectType
objectType} -> Maybe ObjectType
objectType) (\s :: UpdateFacet
s@UpdateFacet' {} Maybe ObjectType
a -> UpdateFacet
s {$sel:objectType:UpdateFacet' :: Maybe ObjectType
objectType = Maybe ObjectType
a} :: UpdateFacet)

-- | The Amazon Resource Name (ARN) that is associated with the Facet. For
-- more information, see arns.
updateFacet_schemaArn :: Lens.Lens' UpdateFacet Prelude.Text
updateFacet_schemaArn :: Lens' UpdateFacet Text
updateFacet_schemaArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateFacet' {Text
schemaArn :: Text
$sel:schemaArn:UpdateFacet' :: UpdateFacet -> Text
schemaArn} -> Text
schemaArn) (\s :: UpdateFacet
s@UpdateFacet' {} Text
a -> UpdateFacet
s {$sel:schemaArn:UpdateFacet' :: Text
schemaArn = Text
a} :: UpdateFacet)

-- | The name of the facet.
updateFacet_name :: Lens.Lens' UpdateFacet Prelude.Text
updateFacet_name :: Lens' UpdateFacet Text
updateFacet_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateFacet' {Text
name :: Text
$sel:name:UpdateFacet' :: UpdateFacet -> Text
name} -> Text
name) (\s :: UpdateFacet
s@UpdateFacet' {} Text
a -> UpdateFacet
s {$sel:name:UpdateFacet' :: Text
name = Text
a} :: UpdateFacet)

instance Core.AWSRequest UpdateFacet where
  type AWSResponse UpdateFacet = UpdateFacetResponse
  request :: (Service -> Service) -> UpdateFacet -> Request UpdateFacet
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 UpdateFacet
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateFacet)))
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 -> UpdateFacetResponse
UpdateFacetResponse'
            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 UpdateFacet where
  hashWithSalt :: Int -> UpdateFacet -> Int
hashWithSalt Int
_salt UpdateFacet' {Maybe [FacetAttributeUpdate]
Maybe ObjectType
Text
name :: Text
schemaArn :: Text
objectType :: Maybe ObjectType
attributeUpdates :: Maybe [FacetAttributeUpdate]
$sel:name:UpdateFacet' :: UpdateFacet -> Text
$sel:schemaArn:UpdateFacet' :: UpdateFacet -> Text
$sel:objectType:UpdateFacet' :: UpdateFacet -> Maybe ObjectType
$sel:attributeUpdates:UpdateFacet' :: UpdateFacet -> Maybe [FacetAttributeUpdate]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [FacetAttributeUpdate]
attributeUpdates
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ObjectType
objectType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
schemaArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

instance Prelude.NFData UpdateFacet where
  rnf :: UpdateFacet -> ()
rnf UpdateFacet' {Maybe [FacetAttributeUpdate]
Maybe ObjectType
Text
name :: Text
schemaArn :: Text
objectType :: Maybe ObjectType
attributeUpdates :: Maybe [FacetAttributeUpdate]
$sel:name:UpdateFacet' :: UpdateFacet -> Text
$sel:schemaArn:UpdateFacet' :: UpdateFacet -> Text
$sel:objectType:UpdateFacet' :: UpdateFacet -> Maybe ObjectType
$sel:attributeUpdates:UpdateFacet' :: UpdateFacet -> Maybe [FacetAttributeUpdate]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [FacetAttributeUpdate]
attributeUpdates
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ObjectType
objectType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
schemaArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name

instance Data.ToHeaders UpdateFacet where
  toHeaders :: UpdateFacet -> ResponseHeaders
toHeaders UpdateFacet' {Maybe [FacetAttributeUpdate]
Maybe ObjectType
Text
name :: Text
schemaArn :: Text
objectType :: Maybe ObjectType
attributeUpdates :: Maybe [FacetAttributeUpdate]
$sel:name:UpdateFacet' :: UpdateFacet -> Text
$sel:schemaArn:UpdateFacet' :: UpdateFacet -> Text
$sel:objectType:UpdateFacet' :: UpdateFacet -> Maybe ObjectType
$sel:attributeUpdates:UpdateFacet' :: UpdateFacet -> Maybe [FacetAttributeUpdate]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [HeaderName
"x-amz-data-partition" forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# Text
schemaArn]

instance Data.ToJSON UpdateFacet where
  toJSON :: UpdateFacet -> Value
toJSON UpdateFacet' {Maybe [FacetAttributeUpdate]
Maybe ObjectType
Text
name :: Text
schemaArn :: Text
objectType :: Maybe ObjectType
attributeUpdates :: Maybe [FacetAttributeUpdate]
$sel:name:UpdateFacet' :: UpdateFacet -> Text
$sel:schemaArn:UpdateFacet' :: UpdateFacet -> Text
$sel:objectType:UpdateFacet' :: UpdateFacet -> Maybe ObjectType
$sel:attributeUpdates:UpdateFacet' :: UpdateFacet -> Maybe [FacetAttributeUpdate]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AttributeUpdates" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [FacetAttributeUpdate]
attributeUpdates,
            (Key
"ObjectType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ObjectType
objectType,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name)
          ]
      )

instance Data.ToPath UpdateFacet where
  toPath :: UpdateFacet -> ByteString
toPath =
    forall a b. a -> b -> a
Prelude.const
      ByteString
"/amazonclouddirectory/2017-01-11/facet"

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

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

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

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

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