{-# 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.CodeBuild.BatchGetProjects
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets information about one or more build projects.
module Amazonka.CodeBuild.BatchGetProjects
  ( -- * Creating a Request
    BatchGetProjects (..),
    newBatchGetProjects,

    -- * Request Lenses
    batchGetProjects_names,

    -- * Destructuring the Response
    BatchGetProjectsResponse (..),
    newBatchGetProjectsResponse,

    -- * Response Lenses
    batchGetProjectsResponse_projects,
    batchGetProjectsResponse_projectsNotFound,
    batchGetProjectsResponse_httpStatus,
  )
where

import Amazonka.CodeBuild.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:/ 'newBatchGetProjects' smart constructor.
data BatchGetProjects = BatchGetProjects'
  { -- | The names or ARNs of the build projects. To get information about a
    -- project shared with your Amazon Web Services account, its ARN must be
    -- specified. You cannot specify a shared project using its name.
    BatchGetProjects -> NonEmpty Text
names :: Prelude.NonEmpty Prelude.Text
  }
  deriving (BatchGetProjects -> BatchGetProjects -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchGetProjects -> BatchGetProjects -> Bool
$c/= :: BatchGetProjects -> BatchGetProjects -> Bool
== :: BatchGetProjects -> BatchGetProjects -> Bool
$c== :: BatchGetProjects -> BatchGetProjects -> Bool
Prelude.Eq, ReadPrec [BatchGetProjects]
ReadPrec BatchGetProjects
Int -> ReadS BatchGetProjects
ReadS [BatchGetProjects]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchGetProjects]
$creadListPrec :: ReadPrec [BatchGetProjects]
readPrec :: ReadPrec BatchGetProjects
$creadPrec :: ReadPrec BatchGetProjects
readList :: ReadS [BatchGetProjects]
$creadList :: ReadS [BatchGetProjects]
readsPrec :: Int -> ReadS BatchGetProjects
$creadsPrec :: Int -> ReadS BatchGetProjects
Prelude.Read, Int -> BatchGetProjects -> ShowS
[BatchGetProjects] -> ShowS
BatchGetProjects -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchGetProjects] -> ShowS
$cshowList :: [BatchGetProjects] -> ShowS
show :: BatchGetProjects -> String
$cshow :: BatchGetProjects -> String
showsPrec :: Int -> BatchGetProjects -> ShowS
$cshowsPrec :: Int -> BatchGetProjects -> ShowS
Prelude.Show, forall x. Rep BatchGetProjects x -> BatchGetProjects
forall x. BatchGetProjects -> Rep BatchGetProjects x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchGetProjects x -> BatchGetProjects
$cfrom :: forall x. BatchGetProjects -> Rep BatchGetProjects x
Prelude.Generic)

-- |
-- Create a value of 'BatchGetProjects' 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:
--
-- 'names', 'batchGetProjects_names' - The names or ARNs of the build projects. To get information about a
-- project shared with your Amazon Web Services account, its ARN must be
-- specified. You cannot specify a shared project using its name.
newBatchGetProjects ::
  -- | 'names'
  Prelude.NonEmpty Prelude.Text ->
  BatchGetProjects
newBatchGetProjects :: NonEmpty Text -> BatchGetProjects
newBatchGetProjects NonEmpty Text
pNames_ =
  BatchGetProjects'
    { $sel:names:BatchGetProjects' :: NonEmpty Text
names =
        forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pNames_
    }

-- | The names or ARNs of the build projects. To get information about a
-- project shared with your Amazon Web Services account, its ARN must be
-- specified. You cannot specify a shared project using its name.
batchGetProjects_names :: Lens.Lens' BatchGetProjects (Prelude.NonEmpty Prelude.Text)
batchGetProjects_names :: Lens' BatchGetProjects (NonEmpty Text)
batchGetProjects_names = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchGetProjects' {NonEmpty Text
names :: NonEmpty Text
$sel:names:BatchGetProjects' :: BatchGetProjects -> NonEmpty Text
names} -> NonEmpty Text
names) (\s :: BatchGetProjects
s@BatchGetProjects' {} NonEmpty Text
a -> BatchGetProjects
s {$sel:names:BatchGetProjects' :: NonEmpty Text
names = NonEmpty Text
a} :: BatchGetProjects) 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 BatchGetProjects where
  type
    AWSResponse BatchGetProjects =
      BatchGetProjectsResponse
  request :: (Service -> Service)
-> BatchGetProjects -> Request BatchGetProjects
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy BatchGetProjects
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BatchGetProjects)))
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 ->
          Maybe [Project]
-> Maybe (NonEmpty Text) -> Int -> BatchGetProjectsResponse
BatchGetProjectsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"projects" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            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
"projectsNotFound")
            forall (f :: * -> *) a b. Applicative f => 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 BatchGetProjects where
  hashWithSalt :: Int -> BatchGetProjects -> Int
hashWithSalt Int
_salt BatchGetProjects' {NonEmpty Text
names :: NonEmpty Text
$sel:names:BatchGetProjects' :: BatchGetProjects -> NonEmpty Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
names

instance Prelude.NFData BatchGetProjects where
  rnf :: BatchGetProjects -> ()
rnf BatchGetProjects' {NonEmpty Text
names :: NonEmpty Text
$sel:names:BatchGetProjects' :: BatchGetProjects -> NonEmpty Text
..} = forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
names

instance Data.ToHeaders BatchGetProjects where
  toHeaders :: BatchGetProjects -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"CodeBuild_20161006.BatchGetProjects" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON BatchGetProjects where
  toJSON :: BatchGetProjects -> Value
toJSON BatchGetProjects' {NonEmpty Text
names :: NonEmpty Text
$sel:names:BatchGetProjects' :: BatchGetProjects -> NonEmpty Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"names" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
names)]
      )

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

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

-- | /See:/ 'newBatchGetProjectsResponse' smart constructor.
data BatchGetProjectsResponse = BatchGetProjectsResponse'
  { -- | Information about the requested build projects.
    BatchGetProjectsResponse -> Maybe [Project]
projects :: Prelude.Maybe [Project],
    -- | The names of build projects for which information could not be found.
    BatchGetProjectsResponse -> Maybe (NonEmpty Text)
projectsNotFound :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | The response's http status code.
    BatchGetProjectsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BatchGetProjectsResponse -> BatchGetProjectsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchGetProjectsResponse -> BatchGetProjectsResponse -> Bool
$c/= :: BatchGetProjectsResponse -> BatchGetProjectsResponse -> Bool
== :: BatchGetProjectsResponse -> BatchGetProjectsResponse -> Bool
$c== :: BatchGetProjectsResponse -> BatchGetProjectsResponse -> Bool
Prelude.Eq, ReadPrec [BatchGetProjectsResponse]
ReadPrec BatchGetProjectsResponse
Int -> ReadS BatchGetProjectsResponse
ReadS [BatchGetProjectsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchGetProjectsResponse]
$creadListPrec :: ReadPrec [BatchGetProjectsResponse]
readPrec :: ReadPrec BatchGetProjectsResponse
$creadPrec :: ReadPrec BatchGetProjectsResponse
readList :: ReadS [BatchGetProjectsResponse]
$creadList :: ReadS [BatchGetProjectsResponse]
readsPrec :: Int -> ReadS BatchGetProjectsResponse
$creadsPrec :: Int -> ReadS BatchGetProjectsResponse
Prelude.Read, Int -> BatchGetProjectsResponse -> ShowS
[BatchGetProjectsResponse] -> ShowS
BatchGetProjectsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchGetProjectsResponse] -> ShowS
$cshowList :: [BatchGetProjectsResponse] -> ShowS
show :: BatchGetProjectsResponse -> String
$cshow :: BatchGetProjectsResponse -> String
showsPrec :: Int -> BatchGetProjectsResponse -> ShowS
$cshowsPrec :: Int -> BatchGetProjectsResponse -> ShowS
Prelude.Show, forall x.
Rep BatchGetProjectsResponse x -> BatchGetProjectsResponse
forall x.
BatchGetProjectsResponse -> Rep BatchGetProjectsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchGetProjectsResponse x -> BatchGetProjectsResponse
$cfrom :: forall x.
BatchGetProjectsResponse -> Rep BatchGetProjectsResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchGetProjectsResponse' 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:
--
-- 'projects', 'batchGetProjectsResponse_projects' - Information about the requested build projects.
--
-- 'projectsNotFound', 'batchGetProjectsResponse_projectsNotFound' - The names of build projects for which information could not be found.
--
-- 'httpStatus', 'batchGetProjectsResponse_httpStatus' - The response's http status code.
newBatchGetProjectsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchGetProjectsResponse
newBatchGetProjectsResponse :: Int -> BatchGetProjectsResponse
newBatchGetProjectsResponse Int
pHttpStatus_ =
  BatchGetProjectsResponse'
    { $sel:projects:BatchGetProjectsResponse' :: Maybe [Project]
projects =
        forall a. Maybe a
Prelude.Nothing,
      $sel:projectsNotFound:BatchGetProjectsResponse' :: Maybe (NonEmpty Text)
projectsNotFound = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchGetProjectsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the requested build projects.
batchGetProjectsResponse_projects :: Lens.Lens' BatchGetProjectsResponse (Prelude.Maybe [Project])
batchGetProjectsResponse_projects :: Lens' BatchGetProjectsResponse (Maybe [Project])
batchGetProjectsResponse_projects = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchGetProjectsResponse' {Maybe [Project]
projects :: Maybe [Project]
$sel:projects:BatchGetProjectsResponse' :: BatchGetProjectsResponse -> Maybe [Project]
projects} -> Maybe [Project]
projects) (\s :: BatchGetProjectsResponse
s@BatchGetProjectsResponse' {} Maybe [Project]
a -> BatchGetProjectsResponse
s {$sel:projects:BatchGetProjectsResponse' :: Maybe [Project]
projects = Maybe [Project]
a} :: BatchGetProjectsResponse) 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 names of build projects for which information could not be found.
batchGetProjectsResponse_projectsNotFound :: Lens.Lens' BatchGetProjectsResponse (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
batchGetProjectsResponse_projectsNotFound :: Lens' BatchGetProjectsResponse (Maybe (NonEmpty Text))
batchGetProjectsResponse_projectsNotFound = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchGetProjectsResponse' {Maybe (NonEmpty Text)
projectsNotFound :: Maybe (NonEmpty Text)
$sel:projectsNotFound:BatchGetProjectsResponse' :: BatchGetProjectsResponse -> Maybe (NonEmpty Text)
projectsNotFound} -> Maybe (NonEmpty Text)
projectsNotFound) (\s :: BatchGetProjectsResponse
s@BatchGetProjectsResponse' {} Maybe (NonEmpty Text)
a -> BatchGetProjectsResponse
s {$sel:projectsNotFound:BatchGetProjectsResponse' :: Maybe (NonEmpty Text)
projectsNotFound = Maybe (NonEmpty Text)
a} :: BatchGetProjectsResponse) 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 response's http status code.
batchGetProjectsResponse_httpStatus :: Lens.Lens' BatchGetProjectsResponse Prelude.Int
batchGetProjectsResponse_httpStatus :: Lens' BatchGetProjectsResponse Int
batchGetProjectsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchGetProjectsResponse' {Int
httpStatus :: Int
$sel:httpStatus:BatchGetProjectsResponse' :: BatchGetProjectsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BatchGetProjectsResponse
s@BatchGetProjectsResponse' {} Int
a -> BatchGetProjectsResponse
s {$sel:httpStatus:BatchGetProjectsResponse' :: Int
httpStatus = Int
a} :: BatchGetProjectsResponse)

instance Prelude.NFData BatchGetProjectsResponse where
  rnf :: BatchGetProjectsResponse -> ()
rnf BatchGetProjectsResponse' {Int
Maybe [Project]
Maybe (NonEmpty Text)
httpStatus :: Int
projectsNotFound :: Maybe (NonEmpty Text)
projects :: Maybe [Project]
$sel:httpStatus:BatchGetProjectsResponse' :: BatchGetProjectsResponse -> Int
$sel:projectsNotFound:BatchGetProjectsResponse' :: BatchGetProjectsResponse -> Maybe (NonEmpty Text)
$sel:projects:BatchGetProjectsResponse' :: BatchGetProjectsResponse -> Maybe [Project]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Project]
projects
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
projectsNotFound
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus