{-# 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.ECRPublic.CreateRepository
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a repository in a public registry. For more information, see
-- <https://docs.aws.amazon.com/AmazonECR/latest/userguide/Repositories.html Amazon ECR repositories>
-- in the /Amazon Elastic Container Registry User Guide/.
module Amazonka.ECRPublic.CreateRepository
  ( -- * Creating a Request
    CreateRepository (..),
    newCreateRepository,

    -- * Request Lenses
    createRepository_catalogData,
    createRepository_tags,
    createRepository_repositoryName,

    -- * Destructuring the Response
    CreateRepositoryResponse (..),
    newCreateRepositoryResponse,

    -- * Response Lenses
    createRepositoryResponse_catalogData,
    createRepositoryResponse_repository,
    createRepositoryResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateRepository' smart constructor.
data CreateRepository = CreateRepository'
  { -- | The details about the repository that are publicly visible in the Amazon
    -- ECR Public Gallery.
    CreateRepository -> Maybe RepositoryCatalogDataInput
catalogData :: Prelude.Maybe RepositoryCatalogDataInput,
    -- | The metadata that you apply to the repository to help you categorize and
    -- organize them. Each tag consists of a key and an optional value, both of
    -- which you define. Tag keys can have a maximum character length of 128
    -- characters, and tag values can have a maximum length of 256 characters.
    CreateRepository -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The name to use for the repository. This appears publicly in the Amazon
    -- ECR Public Gallery. The repository name may be specified on its own
    -- (such as @nginx-web-app@) or it can be prepended with a namespace to
    -- group the repository into a category (such as
    -- @project-a\/nginx-web-app@).
    CreateRepository -> Text
repositoryName :: Prelude.Text
  }
  deriving (CreateRepository -> CreateRepository -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateRepository -> CreateRepository -> Bool
$c/= :: CreateRepository -> CreateRepository -> Bool
== :: CreateRepository -> CreateRepository -> Bool
$c== :: CreateRepository -> CreateRepository -> Bool
Prelude.Eq, ReadPrec [CreateRepository]
ReadPrec CreateRepository
Int -> ReadS CreateRepository
ReadS [CreateRepository]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateRepository]
$creadListPrec :: ReadPrec [CreateRepository]
readPrec :: ReadPrec CreateRepository
$creadPrec :: ReadPrec CreateRepository
readList :: ReadS [CreateRepository]
$creadList :: ReadS [CreateRepository]
readsPrec :: Int -> ReadS CreateRepository
$creadsPrec :: Int -> ReadS CreateRepository
Prelude.Read, Int -> CreateRepository -> ShowS
[CreateRepository] -> ShowS
CreateRepository -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateRepository] -> ShowS
$cshowList :: [CreateRepository] -> ShowS
show :: CreateRepository -> String
$cshow :: CreateRepository -> String
showsPrec :: Int -> CreateRepository -> ShowS
$cshowsPrec :: Int -> CreateRepository -> ShowS
Prelude.Show, forall x. Rep CreateRepository x -> CreateRepository
forall x. CreateRepository -> Rep CreateRepository x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateRepository x -> CreateRepository
$cfrom :: forall x. CreateRepository -> Rep CreateRepository x
Prelude.Generic)

-- |
-- Create a value of 'CreateRepository' 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:
--
-- 'catalogData', 'createRepository_catalogData' - The details about the repository that are publicly visible in the Amazon
-- ECR Public Gallery.
--
-- 'tags', 'createRepository_tags' - The metadata that you apply to the repository to help you categorize and
-- organize them. Each tag consists of a key and an optional value, both of
-- which you define. Tag keys can have a maximum character length of 128
-- characters, and tag values can have a maximum length of 256 characters.
--
-- 'repositoryName', 'createRepository_repositoryName' - The name to use for the repository. This appears publicly in the Amazon
-- ECR Public Gallery. The repository name may be specified on its own
-- (such as @nginx-web-app@) or it can be prepended with a namespace to
-- group the repository into a category (such as
-- @project-a\/nginx-web-app@).
newCreateRepository ::
  -- | 'repositoryName'
  Prelude.Text ->
  CreateRepository
newCreateRepository :: Text -> CreateRepository
newCreateRepository Text
pRepositoryName_ =
  CreateRepository'
    { $sel:catalogData:CreateRepository' :: Maybe RepositoryCatalogDataInput
catalogData = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateRepository' :: Maybe [Tag]
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:repositoryName:CreateRepository' :: Text
repositoryName = Text
pRepositoryName_
    }

-- | The details about the repository that are publicly visible in the Amazon
-- ECR Public Gallery.
createRepository_catalogData :: Lens.Lens' CreateRepository (Prelude.Maybe RepositoryCatalogDataInput)
createRepository_catalogData :: Lens' CreateRepository (Maybe RepositoryCatalogDataInput)
createRepository_catalogData = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRepository' {Maybe RepositoryCatalogDataInput
catalogData :: Maybe RepositoryCatalogDataInput
$sel:catalogData:CreateRepository' :: CreateRepository -> Maybe RepositoryCatalogDataInput
catalogData} -> Maybe RepositoryCatalogDataInput
catalogData) (\s :: CreateRepository
s@CreateRepository' {} Maybe RepositoryCatalogDataInput
a -> CreateRepository
s {$sel:catalogData:CreateRepository' :: Maybe RepositoryCatalogDataInput
catalogData = Maybe RepositoryCatalogDataInput
a} :: CreateRepository)

-- | The metadata that you apply to the repository to help you categorize and
-- organize them. Each tag consists of a key and an optional value, both of
-- which you define. Tag keys can have a maximum character length of 128
-- characters, and tag values can have a maximum length of 256 characters.
createRepository_tags :: Lens.Lens' CreateRepository (Prelude.Maybe [Tag])
createRepository_tags :: Lens' CreateRepository (Maybe [Tag])
createRepository_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRepository' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateRepository' :: CreateRepository -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateRepository
s@CreateRepository' {} Maybe [Tag]
a -> CreateRepository
s {$sel:tags:CreateRepository' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateRepository) 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 name to use for the repository. This appears publicly in the Amazon
-- ECR Public Gallery. The repository name may be specified on its own
-- (such as @nginx-web-app@) or it can be prepended with a namespace to
-- group the repository into a category (such as
-- @project-a\/nginx-web-app@).
createRepository_repositoryName :: Lens.Lens' CreateRepository Prelude.Text
createRepository_repositoryName :: Lens' CreateRepository Text
createRepository_repositoryName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRepository' {Text
repositoryName :: Text
$sel:repositoryName:CreateRepository' :: CreateRepository -> Text
repositoryName} -> Text
repositoryName) (\s :: CreateRepository
s@CreateRepository' {} Text
a -> CreateRepository
s {$sel:repositoryName:CreateRepository' :: Text
repositoryName = Text
a} :: CreateRepository)

instance Core.AWSRequest CreateRepository where
  type
    AWSResponse CreateRepository =
      CreateRepositoryResponse
  request :: (Service -> Service)
-> CreateRepository -> Request CreateRepository
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 CreateRepository
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateRepository)))
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 RepositoryCatalogData
-> Maybe Repository -> Int -> CreateRepositoryResponse
CreateRepositoryResponse'
            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
"catalogData")
            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
"repository")
            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 CreateRepository where
  hashWithSalt :: Int -> CreateRepository -> Int
hashWithSalt Int
_salt CreateRepository' {Maybe [Tag]
Maybe RepositoryCatalogDataInput
Text
repositoryName :: Text
tags :: Maybe [Tag]
catalogData :: Maybe RepositoryCatalogDataInput
$sel:repositoryName:CreateRepository' :: CreateRepository -> Text
$sel:tags:CreateRepository' :: CreateRepository -> Maybe [Tag]
$sel:catalogData:CreateRepository' :: CreateRepository -> Maybe RepositoryCatalogDataInput
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RepositoryCatalogDataInput
catalogData
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Tag]
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
repositoryName

instance Prelude.NFData CreateRepository where
  rnf :: CreateRepository -> ()
rnf CreateRepository' {Maybe [Tag]
Maybe RepositoryCatalogDataInput
Text
repositoryName :: Text
tags :: Maybe [Tag]
catalogData :: Maybe RepositoryCatalogDataInput
$sel:repositoryName:CreateRepository' :: CreateRepository -> Text
$sel:tags:CreateRepository' :: CreateRepository -> Maybe [Tag]
$sel:catalogData:CreateRepository' :: CreateRepository -> Maybe RepositoryCatalogDataInput
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe RepositoryCatalogDataInput
catalogData
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Tag]
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
repositoryName

instance Data.ToHeaders CreateRepository where
  toHeaders :: CreateRepository -> 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
"SpencerFrontendService.CreateRepository" ::
                          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 CreateRepository where
  toJSON :: CreateRepository -> Value
toJSON CreateRepository' {Maybe [Tag]
Maybe RepositoryCatalogDataInput
Text
repositoryName :: Text
tags :: Maybe [Tag]
catalogData :: Maybe RepositoryCatalogDataInput
$sel:repositoryName:CreateRepository' :: CreateRepository -> Text
$sel:tags:CreateRepository' :: CreateRepository -> Maybe [Tag]
$sel:catalogData:CreateRepository' :: CreateRepository -> Maybe RepositoryCatalogDataInput
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"catalogData" 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 RepositoryCatalogDataInput
catalogData,
            (Key
"tags" 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 [Tag]
tags,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"repositoryName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
repositoryName)
          ]
      )

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

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

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

-- |
-- Create a value of 'CreateRepositoryResponse' 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:
--
-- 'catalogData', 'createRepositoryResponse_catalogData' - Undocumented member.
--
-- 'repository', 'createRepositoryResponse_repository' - The repository that was created.
--
-- 'httpStatus', 'createRepositoryResponse_httpStatus' - The response's http status code.
newCreateRepositoryResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateRepositoryResponse
newCreateRepositoryResponse :: Int -> CreateRepositoryResponse
newCreateRepositoryResponse Int
pHttpStatus_ =
  CreateRepositoryResponse'
    { $sel:catalogData:CreateRepositoryResponse' :: Maybe RepositoryCatalogData
catalogData =
        forall a. Maybe a
Prelude.Nothing,
      $sel:repository:CreateRepositoryResponse' :: Maybe Repository
repository = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateRepositoryResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Undocumented member.
createRepositoryResponse_catalogData :: Lens.Lens' CreateRepositoryResponse (Prelude.Maybe RepositoryCatalogData)
createRepositoryResponse_catalogData :: Lens' CreateRepositoryResponse (Maybe RepositoryCatalogData)
createRepositoryResponse_catalogData = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRepositoryResponse' {Maybe RepositoryCatalogData
catalogData :: Maybe RepositoryCatalogData
$sel:catalogData:CreateRepositoryResponse' :: CreateRepositoryResponse -> Maybe RepositoryCatalogData
catalogData} -> Maybe RepositoryCatalogData
catalogData) (\s :: CreateRepositoryResponse
s@CreateRepositoryResponse' {} Maybe RepositoryCatalogData
a -> CreateRepositoryResponse
s {$sel:catalogData:CreateRepositoryResponse' :: Maybe RepositoryCatalogData
catalogData = Maybe RepositoryCatalogData
a} :: CreateRepositoryResponse)

-- | The repository that was created.
createRepositoryResponse_repository :: Lens.Lens' CreateRepositoryResponse (Prelude.Maybe Repository)
createRepositoryResponse_repository :: Lens' CreateRepositoryResponse (Maybe Repository)
createRepositoryResponse_repository = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRepositoryResponse' {Maybe Repository
repository :: Maybe Repository
$sel:repository:CreateRepositoryResponse' :: CreateRepositoryResponse -> Maybe Repository
repository} -> Maybe Repository
repository) (\s :: CreateRepositoryResponse
s@CreateRepositoryResponse' {} Maybe Repository
a -> CreateRepositoryResponse
s {$sel:repository:CreateRepositoryResponse' :: Maybe Repository
repository = Maybe Repository
a} :: CreateRepositoryResponse)

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

instance Prelude.NFData CreateRepositoryResponse where
  rnf :: CreateRepositoryResponse -> ()
rnf CreateRepositoryResponse' {Int
Maybe Repository
Maybe RepositoryCatalogData
httpStatus :: Int
repository :: Maybe Repository
catalogData :: Maybe RepositoryCatalogData
$sel:httpStatus:CreateRepositoryResponse' :: CreateRepositoryResponse -> Int
$sel:repository:CreateRepositoryResponse' :: CreateRepositoryResponse -> Maybe Repository
$sel:catalogData:CreateRepositoryResponse' :: CreateRepositoryResponse -> Maybe RepositoryCatalogData
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe RepositoryCatalogData
catalogData
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Repository
repository
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus