{-# 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.CodeStar.TagProject
-- 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 tags to a project.
module Amazonka.CodeStar.TagProject
  ( -- * Creating a Request
    TagProject (..),
    newTagProject,

    -- * Request Lenses
    tagProject_id,
    tagProject_tags,

    -- * Destructuring the Response
    TagProjectResponse (..),
    newTagProjectResponse,

    -- * Response Lenses
    tagProjectResponse_tags,
    tagProjectResponse_httpStatus,
  )
where

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

-- | /See:/ 'newTagProject' smart constructor.
data TagProject = TagProject'
  { -- | The ID of the project you want to add a tag to.
    TagProject -> Text
id :: Prelude.Text,
    -- | The tags you want to add to the project.
    TagProject -> HashMap Text Text
tags :: Prelude.HashMap Prelude.Text Prelude.Text
  }
  deriving (TagProject -> TagProject -> Bool
(TagProject -> TagProject -> Bool)
-> (TagProject -> TagProject -> Bool) -> Eq TagProject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TagProject -> TagProject -> Bool
$c/= :: TagProject -> TagProject -> Bool
== :: TagProject -> TagProject -> Bool
$c== :: TagProject -> TagProject -> Bool
Prelude.Eq, ReadPrec [TagProject]
ReadPrec TagProject
Int -> ReadS TagProject
ReadS [TagProject]
(Int -> ReadS TagProject)
-> ReadS [TagProject]
-> ReadPrec TagProject
-> ReadPrec [TagProject]
-> Read TagProject
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TagProject]
$creadListPrec :: ReadPrec [TagProject]
readPrec :: ReadPrec TagProject
$creadPrec :: ReadPrec TagProject
readList :: ReadS [TagProject]
$creadList :: ReadS [TagProject]
readsPrec :: Int -> ReadS TagProject
$creadsPrec :: Int -> ReadS TagProject
Prelude.Read, Int -> TagProject -> ShowS
[TagProject] -> ShowS
TagProject -> String
(Int -> TagProject -> ShowS)
-> (TagProject -> String)
-> ([TagProject] -> ShowS)
-> Show TagProject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TagProject] -> ShowS
$cshowList :: [TagProject] -> ShowS
show :: TagProject -> String
$cshow :: TagProject -> String
showsPrec :: Int -> TagProject -> ShowS
$cshowsPrec :: Int -> TagProject -> ShowS
Prelude.Show, (forall x. TagProject -> Rep TagProject x)
-> (forall x. Rep TagProject x -> TagProject) -> Generic TagProject
forall x. Rep TagProject x -> TagProject
forall x. TagProject -> Rep TagProject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TagProject x -> TagProject
$cfrom :: forall x. TagProject -> Rep TagProject x
Prelude.Generic)

-- |
-- Create a value of 'TagProject' 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:
--
-- 'id', 'tagProject_id' - The ID of the project you want to add a tag to.
--
-- 'tags', 'tagProject_tags' - The tags you want to add to the project.
newTagProject ::
  -- | 'id'
  Prelude.Text ->
  TagProject
newTagProject :: Text -> TagProject
newTagProject Text
pId_ =
  TagProject' :: Text -> HashMap Text Text -> TagProject
TagProject' {$sel:id:TagProject' :: Text
id = Text
pId_, $sel:tags:TagProject' :: HashMap Text Text
tags = HashMap Text Text
forall a. Monoid a => a
Prelude.mempty}

-- | The ID of the project you want to add a tag to.
tagProject_id :: Lens.Lens' TagProject Prelude.Text
tagProject_id :: (Text -> f Text) -> TagProject -> f TagProject
tagProject_id = (TagProject -> Text)
-> (TagProject -> Text -> TagProject)
-> Lens TagProject TagProject Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagProject' {Text
id :: Text
$sel:id:TagProject' :: TagProject -> Text
id} -> Text
id) (\s :: TagProject
s@TagProject' {} Text
a -> TagProject
s {$sel:id:TagProject' :: Text
id = Text
a} :: TagProject)

-- | The tags you want to add to the project.
tagProject_tags :: Lens.Lens' TagProject (Prelude.HashMap Prelude.Text Prelude.Text)
tagProject_tags :: (HashMap Text Text -> f (HashMap Text Text))
-> TagProject -> f TagProject
tagProject_tags = (TagProject -> HashMap Text Text)
-> (TagProject -> HashMap Text Text -> TagProject)
-> Lens
     TagProject TagProject (HashMap Text Text) (HashMap Text Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagProject' {HashMap Text Text
tags :: HashMap Text Text
$sel:tags:TagProject' :: TagProject -> HashMap Text Text
tags} -> HashMap Text Text
tags) (\s :: TagProject
s@TagProject' {} HashMap Text Text
a -> TagProject
s {$sel:tags:TagProject' :: HashMap Text Text
tags = HashMap Text Text
a} :: TagProject) ((HashMap Text Text -> f (HashMap Text Text))
 -> TagProject -> f TagProject)
-> ((HashMap Text Text -> f (HashMap Text Text))
    -> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> TagProject
-> f TagProject
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest TagProject where
  type AWSResponse TagProject = TagProjectResponse
  request :: TagProject -> Request TagProject
request = Service -> TagProject -> Request TagProject
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy TagProject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse TagProject)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse TagProject))
-> Logger
-> Service
-> Proxy TagProject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse TagProject)))
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 (HashMap Text Text) -> Int -> TagProjectResponse
TagProjectResponse'
            (Maybe (HashMap Text Text) -> Int -> TagProjectResponse)
-> Either String (Maybe (HashMap Text Text))
-> Either String (Int -> TagProjectResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"tags" Either String (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text)
-> Either String (Maybe (HashMap Text Text))
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> TagProjectResponse)
-> Either String Int -> Either String TagProjectResponse
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 TagProject

instance Prelude.NFData TagProject

instance Core.ToHeaders TagProject where
  toHeaders :: TagProject -> ResponseHeaders
toHeaders =
    ResponseHeaders -> TagProject -> 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
"CodeStar_20170419.TagProject" ::
                          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 TagProject where
  toJSON :: TagProject -> Value
toJSON TagProject' {Text
HashMap Text Text
tags :: HashMap Text Text
id :: Text
$sel:tags:TagProject' :: TagProject -> HashMap Text Text
$sel:id:TagProject' :: TagProject -> Text
..} =
    [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
"id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"tags" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
tags)
          ]
      )

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

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

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

-- |
-- Create a value of 'TagProjectResponse' 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', 'tagProjectResponse_tags' - The tags for the project.
--
-- 'httpStatus', 'tagProjectResponse_httpStatus' - The response's http status code.
newTagProjectResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  TagProjectResponse
newTagProjectResponse :: Int -> TagProjectResponse
newTagProjectResponse Int
pHttpStatus_ =
  TagProjectResponse' :: Maybe (HashMap Text Text) -> Int -> TagProjectResponse
TagProjectResponse'
    { $sel:tags:TagProjectResponse' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:TagProjectResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The tags for the project.
tagProjectResponse_tags :: Lens.Lens' TagProjectResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
tagProjectResponse_tags :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> TagProjectResponse -> f TagProjectResponse
tagProjectResponse_tags = (TagProjectResponse -> Maybe (HashMap Text Text))
-> (TagProjectResponse
    -> Maybe (HashMap Text Text) -> TagProjectResponse)
-> Lens
     TagProjectResponse
     TagProjectResponse
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagProjectResponse' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:TagProjectResponse' :: TagProjectResponse -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: TagProjectResponse
s@TagProjectResponse' {} Maybe (HashMap Text Text)
a -> TagProjectResponse
s {$sel:tags:TagProjectResponse' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: TagProjectResponse) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> TagProjectResponse -> f TagProjectResponse)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> TagProjectResponse
-> f TagProjectResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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 AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData TagProjectResponse