{-# 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.MachineLearning.AddTags
-- 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)
--
-- Adds one or more tags to an object, up to a limit of 10. Each tag
-- consists of a key and an optional value. If you add a tag using a key
-- that is already associated with the ML object, @AddTags@ updates the
-- tag\'s value.
module Amazonka.MachineLearning.AddTags
  ( -- * Creating a Request
    AddTags (..),
    newAddTags,

    -- * Request Lenses
    addTags_tags,
    addTags_resourceId,
    addTags_resourceType,

    -- * Destructuring the Response
    AddTagsResponse (..),
    newAddTagsResponse,

    -- * Response Lenses
    addTagsResponse_resourceId,
    addTagsResponse_resourceType,
    addTagsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newAddTags' smart constructor.
data AddTags = AddTags'
  { -- | The key-value pairs to use to create tags. If you specify a key without
    -- specifying a value, Amazon ML creates a tag with the specified key and a
    -- value of null.
    AddTags -> [Tag]
tags :: [Tag],
    -- | The ID of the ML object to tag. For example, @exampleModelId@.
    AddTags -> Text
resourceId :: Prelude.Text,
    -- | The type of the ML object to tag.
    AddTags -> TaggableResourceType
resourceType :: TaggableResourceType
  }
  deriving (AddTags -> AddTags -> Bool
(AddTags -> AddTags -> Bool)
-> (AddTags -> AddTags -> Bool) -> Eq AddTags
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddTags -> AddTags -> Bool
$c/= :: AddTags -> AddTags -> Bool
== :: AddTags -> AddTags -> Bool
$c== :: AddTags -> AddTags -> Bool
Prelude.Eq, ReadPrec [AddTags]
ReadPrec AddTags
Int -> ReadS AddTags
ReadS [AddTags]
(Int -> ReadS AddTags)
-> ReadS [AddTags]
-> ReadPrec AddTags
-> ReadPrec [AddTags]
-> Read AddTags
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddTags]
$creadListPrec :: ReadPrec [AddTags]
readPrec :: ReadPrec AddTags
$creadPrec :: ReadPrec AddTags
readList :: ReadS [AddTags]
$creadList :: ReadS [AddTags]
readsPrec :: Int -> ReadS AddTags
$creadsPrec :: Int -> ReadS AddTags
Prelude.Read, Int -> AddTags -> ShowS
[AddTags] -> ShowS
AddTags -> String
(Int -> AddTags -> ShowS)
-> (AddTags -> String) -> ([AddTags] -> ShowS) -> Show AddTags
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddTags] -> ShowS
$cshowList :: [AddTags] -> ShowS
show :: AddTags -> String
$cshow :: AddTags -> String
showsPrec :: Int -> AddTags -> ShowS
$cshowsPrec :: Int -> AddTags -> ShowS
Prelude.Show, (forall x. AddTags -> Rep AddTags x)
-> (forall x. Rep AddTags x -> AddTags) -> Generic AddTags
forall x. Rep AddTags x -> AddTags
forall x. AddTags -> Rep AddTags x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AddTags x -> AddTags
$cfrom :: forall x. AddTags -> Rep AddTags x
Prelude.Generic)

-- |
-- Create a value of 'AddTags' 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:
--
-- 'tags', 'addTags_tags' - The key-value pairs to use to create tags. If you specify a key without
-- specifying a value, Amazon ML creates a tag with the specified key and a
-- value of null.
--
-- 'resourceId', 'addTags_resourceId' - The ID of the ML object to tag. For example, @exampleModelId@.
--
-- 'resourceType', 'addTags_resourceType' - The type of the ML object to tag.
newAddTags ::
  -- | 'resourceId'
  Prelude.Text ->
  -- | 'resourceType'
  TaggableResourceType ->
  AddTags
newAddTags :: Text -> TaggableResourceType -> AddTags
newAddTags Text
pResourceId_ TaggableResourceType
pResourceType_ =
  AddTags' :: [Tag] -> Text -> TaggableResourceType -> AddTags
AddTags'
    { $sel:tags:AddTags' :: [Tag]
tags = [Tag]
forall a. Monoid a => a
Prelude.mempty,
      $sel:resourceId:AddTags' :: Text
resourceId = Text
pResourceId_,
      $sel:resourceType:AddTags' :: TaggableResourceType
resourceType = TaggableResourceType
pResourceType_
    }

-- | The key-value pairs to use to create tags. If you specify a key without
-- specifying a value, Amazon ML creates a tag with the specified key and a
-- value of null.
addTags_tags :: Lens.Lens' AddTags [Tag]
addTags_tags :: ([Tag] -> f [Tag]) -> AddTags -> f AddTags
addTags_tags = (AddTags -> [Tag])
-> (AddTags -> [Tag] -> AddTags)
-> Lens AddTags AddTags [Tag] [Tag]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddTags' {[Tag]
tags :: [Tag]
$sel:tags:AddTags' :: AddTags -> [Tag]
tags} -> [Tag]
tags) (\s :: AddTags
s@AddTags' {} [Tag]
a -> AddTags
s {$sel:tags:AddTags' :: [Tag]
tags = [Tag]
a} :: AddTags) (([Tag] -> f [Tag]) -> AddTags -> f AddTags)
-> (([Tag] -> f [Tag]) -> [Tag] -> f [Tag])
-> ([Tag] -> f [Tag])
-> AddTags
-> f AddTags
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Tag] -> f [Tag]) -> [Tag] -> f [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ID of the ML object to tag. For example, @exampleModelId@.
addTags_resourceId :: Lens.Lens' AddTags Prelude.Text
addTags_resourceId :: (Text -> f Text) -> AddTags -> f AddTags
addTags_resourceId = (AddTags -> Text)
-> (AddTags -> Text -> AddTags) -> Lens AddTags AddTags Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddTags' {Text
resourceId :: Text
$sel:resourceId:AddTags' :: AddTags -> Text
resourceId} -> Text
resourceId) (\s :: AddTags
s@AddTags' {} Text
a -> AddTags
s {$sel:resourceId:AddTags' :: Text
resourceId = Text
a} :: AddTags)

-- | The type of the ML object to tag.
addTags_resourceType :: Lens.Lens' AddTags TaggableResourceType
addTags_resourceType :: (TaggableResourceType -> f TaggableResourceType)
-> AddTags -> f AddTags
addTags_resourceType = (AddTags -> TaggableResourceType)
-> (AddTags -> TaggableResourceType -> AddTags)
-> Lens AddTags AddTags TaggableResourceType TaggableResourceType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddTags' {TaggableResourceType
resourceType :: TaggableResourceType
$sel:resourceType:AddTags' :: AddTags -> TaggableResourceType
resourceType} -> TaggableResourceType
resourceType) (\s :: AddTags
s@AddTags' {} TaggableResourceType
a -> AddTags
s {$sel:resourceType:AddTags' :: TaggableResourceType
resourceType = TaggableResourceType
a} :: AddTags)

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

instance Prelude.NFData AddTags

instance Core.ToHeaders AddTags where
  toHeaders :: AddTags -> ResponseHeaders
toHeaders =
    ResponseHeaders -> AddTags -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"AmazonML_20141212.AddTags" :: Prelude.ByteString),
            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 AddTags where
  toJSON :: AddTags -> Value
toJSON AddTags' {[Tag]
Text
TaggableResourceType
resourceType :: TaggableResourceType
resourceId :: Text
tags :: [Tag]
$sel:resourceType:AddTags' :: AddTags -> TaggableResourceType
$sel:resourceId:AddTags' :: AddTags -> Text
$sel:tags:AddTags' :: AddTags -> [Tag]
..} =
    [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
"Tags" Text -> [Tag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Tag]
tags),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ResourceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
resourceId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ResourceType" Text -> TaggableResourceType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= TaggableResourceType
resourceType)
          ]
      )

instance Core.ToPath AddTags where
  toPath :: AddTags -> ByteString
toPath = ByteString -> AddTags -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | Amazon ML returns the following elements.
--
-- /See:/ 'newAddTagsResponse' smart constructor.
data AddTagsResponse = AddTagsResponse'
  { -- | The ID of the ML object that was tagged.
    AddTagsResponse -> Maybe Text
resourceId :: Prelude.Maybe Prelude.Text,
    -- | The type of the ML object that was tagged.
    AddTagsResponse -> Maybe TaggableResourceType
resourceType :: Prelude.Maybe TaggableResourceType,
    -- | The response's http status code.
    AddTagsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AddTagsResponse -> AddTagsResponse -> Bool
(AddTagsResponse -> AddTagsResponse -> Bool)
-> (AddTagsResponse -> AddTagsResponse -> Bool)
-> Eq AddTagsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddTagsResponse -> AddTagsResponse -> Bool
$c/= :: AddTagsResponse -> AddTagsResponse -> Bool
== :: AddTagsResponse -> AddTagsResponse -> Bool
$c== :: AddTagsResponse -> AddTagsResponse -> Bool
Prelude.Eq, ReadPrec [AddTagsResponse]
ReadPrec AddTagsResponse
Int -> ReadS AddTagsResponse
ReadS [AddTagsResponse]
(Int -> ReadS AddTagsResponse)
-> ReadS [AddTagsResponse]
-> ReadPrec AddTagsResponse
-> ReadPrec [AddTagsResponse]
-> Read AddTagsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddTagsResponse]
$creadListPrec :: ReadPrec [AddTagsResponse]
readPrec :: ReadPrec AddTagsResponse
$creadPrec :: ReadPrec AddTagsResponse
readList :: ReadS [AddTagsResponse]
$creadList :: ReadS [AddTagsResponse]
readsPrec :: Int -> ReadS AddTagsResponse
$creadsPrec :: Int -> ReadS AddTagsResponse
Prelude.Read, Int -> AddTagsResponse -> ShowS
[AddTagsResponse] -> ShowS
AddTagsResponse -> String
(Int -> AddTagsResponse -> ShowS)
-> (AddTagsResponse -> String)
-> ([AddTagsResponse] -> ShowS)
-> Show AddTagsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddTagsResponse] -> ShowS
$cshowList :: [AddTagsResponse] -> ShowS
show :: AddTagsResponse -> String
$cshow :: AddTagsResponse -> String
showsPrec :: Int -> AddTagsResponse -> ShowS
$cshowsPrec :: Int -> AddTagsResponse -> ShowS
Prelude.Show, (forall x. AddTagsResponse -> Rep AddTagsResponse x)
-> (forall x. Rep AddTagsResponse x -> AddTagsResponse)
-> Generic AddTagsResponse
forall x. Rep AddTagsResponse x -> AddTagsResponse
forall x. AddTagsResponse -> Rep AddTagsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AddTagsResponse x -> AddTagsResponse
$cfrom :: forall x. AddTagsResponse -> Rep AddTagsResponse x
Prelude.Generic)

-- |
-- Create a value of 'AddTagsResponse' 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:
--
-- 'resourceId', 'addTagsResponse_resourceId' - The ID of the ML object that was tagged.
--
-- 'resourceType', 'addTagsResponse_resourceType' - The type of the ML object that was tagged.
--
-- 'httpStatus', 'addTagsResponse_httpStatus' - The response's http status code.
newAddTagsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AddTagsResponse
newAddTagsResponse :: Int -> AddTagsResponse
newAddTagsResponse Int
pHttpStatus_ =
  AddTagsResponse' :: Maybe Text -> Maybe TaggableResourceType -> Int -> AddTagsResponse
AddTagsResponse'
    { $sel:resourceId:AddTagsResponse' :: Maybe Text
resourceId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:resourceType:AddTagsResponse' :: Maybe TaggableResourceType
resourceType = Maybe TaggableResourceType
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AddTagsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ID of the ML object that was tagged.
addTagsResponse_resourceId :: Lens.Lens' AddTagsResponse (Prelude.Maybe Prelude.Text)
addTagsResponse_resourceId :: (Maybe Text -> f (Maybe Text))
-> AddTagsResponse -> f AddTagsResponse
addTagsResponse_resourceId = (AddTagsResponse -> Maybe Text)
-> (AddTagsResponse -> Maybe Text -> AddTagsResponse)
-> Lens AddTagsResponse AddTagsResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddTagsResponse' {Maybe Text
resourceId :: Maybe Text
$sel:resourceId:AddTagsResponse' :: AddTagsResponse -> Maybe Text
resourceId} -> Maybe Text
resourceId) (\s :: AddTagsResponse
s@AddTagsResponse' {} Maybe Text
a -> AddTagsResponse
s {$sel:resourceId:AddTagsResponse' :: Maybe Text
resourceId = Maybe Text
a} :: AddTagsResponse)

-- | The type of the ML object that was tagged.
addTagsResponse_resourceType :: Lens.Lens' AddTagsResponse (Prelude.Maybe TaggableResourceType)
addTagsResponse_resourceType :: (Maybe TaggableResourceType -> f (Maybe TaggableResourceType))
-> AddTagsResponse -> f AddTagsResponse
addTagsResponse_resourceType = (AddTagsResponse -> Maybe TaggableResourceType)
-> (AddTagsResponse
    -> Maybe TaggableResourceType -> AddTagsResponse)
-> Lens
     AddTagsResponse
     AddTagsResponse
     (Maybe TaggableResourceType)
     (Maybe TaggableResourceType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddTagsResponse' {Maybe TaggableResourceType
resourceType :: Maybe TaggableResourceType
$sel:resourceType:AddTagsResponse' :: AddTagsResponse -> Maybe TaggableResourceType
resourceType} -> Maybe TaggableResourceType
resourceType) (\s :: AddTagsResponse
s@AddTagsResponse' {} Maybe TaggableResourceType
a -> AddTagsResponse
s {$sel:resourceType:AddTagsResponse' :: Maybe TaggableResourceType
resourceType = Maybe TaggableResourceType
a} :: AddTagsResponse)

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

instance Prelude.NFData AddTagsResponse