{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.AppRunner.Types.ImageRepository
-- 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)
module Amazonka.AppRunner.Types.ImageRepository where

import Amazonka.AppRunner.Types.ImageConfiguration
import Amazonka.AppRunner.Types.ImageRepositoryType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes a source image repository.
--
-- /See:/ 'newImageRepository' smart constructor.
data ImageRepository = ImageRepository'
  { -- | Configuration for running the identified image.
    ImageRepository -> Maybe ImageConfiguration
imageConfiguration :: Prelude.Maybe ImageConfiguration,
    -- | The identifier of an image.
    --
    -- For an image in Amazon Elastic Container Registry (Amazon ECR), this is
    -- an image name. For the image name format, see
    -- <https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-pull-ecr-image.html Pulling an image>
    -- in the /Amazon ECR User Guide/.
    ImageRepository -> Text
imageIdentifier :: Prelude.Text,
    -- | The type of the image repository. This reflects the repository provider
    -- and whether the repository is private or public.
    ImageRepository -> ImageRepositoryType
imageRepositoryType :: ImageRepositoryType
  }
  deriving (ImageRepository -> ImageRepository -> Bool
(ImageRepository -> ImageRepository -> Bool)
-> (ImageRepository -> ImageRepository -> Bool)
-> Eq ImageRepository
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImageRepository -> ImageRepository -> Bool
$c/= :: ImageRepository -> ImageRepository -> Bool
== :: ImageRepository -> ImageRepository -> Bool
$c== :: ImageRepository -> ImageRepository -> Bool
Prelude.Eq, Int -> ImageRepository -> ShowS
[ImageRepository] -> ShowS
ImageRepository -> String
(Int -> ImageRepository -> ShowS)
-> (ImageRepository -> String)
-> ([ImageRepository] -> ShowS)
-> Show ImageRepository
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImageRepository] -> ShowS
$cshowList :: [ImageRepository] -> ShowS
show :: ImageRepository -> String
$cshow :: ImageRepository -> String
showsPrec :: Int -> ImageRepository -> ShowS
$cshowsPrec :: Int -> ImageRepository -> ShowS
Prelude.Show, (forall x. ImageRepository -> Rep ImageRepository x)
-> (forall x. Rep ImageRepository x -> ImageRepository)
-> Generic ImageRepository
forall x. Rep ImageRepository x -> ImageRepository
forall x. ImageRepository -> Rep ImageRepository x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ImageRepository x -> ImageRepository
$cfrom :: forall x. ImageRepository -> Rep ImageRepository x
Prelude.Generic)

-- |
-- Create a value of 'ImageRepository' 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:
--
-- 'imageConfiguration', 'imageRepository_imageConfiguration' - Configuration for running the identified image.
--
-- 'imageIdentifier', 'imageRepository_imageIdentifier' - The identifier of an image.
--
-- For an image in Amazon Elastic Container Registry (Amazon ECR), this is
-- an image name. For the image name format, see
-- <https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-pull-ecr-image.html Pulling an image>
-- in the /Amazon ECR User Guide/.
--
-- 'imageRepositoryType', 'imageRepository_imageRepositoryType' - The type of the image repository. This reflects the repository provider
-- and whether the repository is private or public.
newImageRepository ::
  -- | 'imageIdentifier'
  Prelude.Text ->
  -- | 'imageRepositoryType'
  ImageRepositoryType ->
  ImageRepository
newImageRepository :: Text -> ImageRepositoryType -> ImageRepository
newImageRepository
  Text
pImageIdentifier_
  ImageRepositoryType
pImageRepositoryType_ =
    ImageRepository' :: Maybe ImageConfiguration
-> Text -> ImageRepositoryType -> ImageRepository
ImageRepository'
      { $sel:imageConfiguration:ImageRepository' :: Maybe ImageConfiguration
imageConfiguration =
          Maybe ImageConfiguration
forall a. Maybe a
Prelude.Nothing,
        $sel:imageIdentifier:ImageRepository' :: Text
imageIdentifier = Text
pImageIdentifier_,
        $sel:imageRepositoryType:ImageRepository' :: ImageRepositoryType
imageRepositoryType = ImageRepositoryType
pImageRepositoryType_
      }

-- | Configuration for running the identified image.
imageRepository_imageConfiguration :: Lens.Lens' ImageRepository (Prelude.Maybe ImageConfiguration)
imageRepository_imageConfiguration :: (Maybe ImageConfiguration -> f (Maybe ImageConfiguration))
-> ImageRepository -> f ImageRepository
imageRepository_imageConfiguration = (ImageRepository -> Maybe ImageConfiguration)
-> (ImageRepository -> Maybe ImageConfiguration -> ImageRepository)
-> Lens
     ImageRepository
     ImageRepository
     (Maybe ImageConfiguration)
     (Maybe ImageConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageRepository' {Maybe ImageConfiguration
imageConfiguration :: Maybe ImageConfiguration
$sel:imageConfiguration:ImageRepository' :: ImageRepository -> Maybe ImageConfiguration
imageConfiguration} -> Maybe ImageConfiguration
imageConfiguration) (\s :: ImageRepository
s@ImageRepository' {} Maybe ImageConfiguration
a -> ImageRepository
s {$sel:imageConfiguration:ImageRepository' :: Maybe ImageConfiguration
imageConfiguration = Maybe ImageConfiguration
a} :: ImageRepository)

-- | The identifier of an image.
--
-- For an image in Amazon Elastic Container Registry (Amazon ECR), this is
-- an image name. For the image name format, see
-- <https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-pull-ecr-image.html Pulling an image>
-- in the /Amazon ECR User Guide/.
imageRepository_imageIdentifier :: Lens.Lens' ImageRepository Prelude.Text
imageRepository_imageIdentifier :: (Text -> f Text) -> ImageRepository -> f ImageRepository
imageRepository_imageIdentifier = (ImageRepository -> Text)
-> (ImageRepository -> Text -> ImageRepository)
-> Lens ImageRepository ImageRepository Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageRepository' {Text
imageIdentifier :: Text
$sel:imageIdentifier:ImageRepository' :: ImageRepository -> Text
imageIdentifier} -> Text
imageIdentifier) (\s :: ImageRepository
s@ImageRepository' {} Text
a -> ImageRepository
s {$sel:imageIdentifier:ImageRepository' :: Text
imageIdentifier = Text
a} :: ImageRepository)

-- | The type of the image repository. This reflects the repository provider
-- and whether the repository is private or public.
imageRepository_imageRepositoryType :: Lens.Lens' ImageRepository ImageRepositoryType
imageRepository_imageRepositoryType :: (ImageRepositoryType -> f ImageRepositoryType)
-> ImageRepository -> f ImageRepository
imageRepository_imageRepositoryType = (ImageRepository -> ImageRepositoryType)
-> (ImageRepository -> ImageRepositoryType -> ImageRepository)
-> Lens
     ImageRepository
     ImageRepository
     ImageRepositoryType
     ImageRepositoryType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageRepository' {ImageRepositoryType
imageRepositoryType :: ImageRepositoryType
$sel:imageRepositoryType:ImageRepository' :: ImageRepository -> ImageRepositoryType
imageRepositoryType} -> ImageRepositoryType
imageRepositoryType) (\s :: ImageRepository
s@ImageRepository' {} ImageRepositoryType
a -> ImageRepository
s {$sel:imageRepositoryType:ImageRepository' :: ImageRepositoryType
imageRepositoryType = ImageRepositoryType
a} :: ImageRepository)

instance Core.FromJSON ImageRepository where
  parseJSON :: Value -> Parser ImageRepository
parseJSON =
    String
-> (Object -> Parser ImageRepository)
-> Value
-> Parser ImageRepository
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ImageRepository"
      ( \Object
x ->
          Maybe ImageConfiguration
-> Text -> ImageRepositoryType -> ImageRepository
ImageRepository'
            (Maybe ImageConfiguration
 -> Text -> ImageRepositoryType -> ImageRepository)
-> Parser (Maybe ImageConfiguration)
-> Parser (Text -> ImageRepositoryType -> ImageRepository)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ImageConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ImageConfiguration")
            Parser (Text -> ImageRepositoryType -> ImageRepository)
-> Parser Text -> Parser (ImageRepositoryType -> ImageRepository)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ImageIdentifier")
            Parser (ImageRepositoryType -> ImageRepository)
-> Parser ImageRepositoryType -> Parser ImageRepository
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ImageRepositoryType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ImageRepositoryType")
      )

instance Prelude.Hashable ImageRepository

instance Prelude.NFData ImageRepository

instance Core.ToJSON ImageRepository where
  toJSON :: ImageRepository -> Value
toJSON ImageRepository' {Maybe ImageConfiguration
Text
ImageRepositoryType
imageRepositoryType :: ImageRepositoryType
imageIdentifier :: Text
imageConfiguration :: Maybe ImageConfiguration
$sel:imageRepositoryType:ImageRepository' :: ImageRepository -> ImageRepositoryType
$sel:imageIdentifier:ImageRepository' :: ImageRepository -> Text
$sel:imageConfiguration:ImageRepository' :: ImageRepository -> Maybe ImageConfiguration
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ImageConfiguration" Text -> ImageConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ImageConfiguration -> Pair)
-> Maybe ImageConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ImageConfiguration
imageConfiguration,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ImageIdentifier" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
imageIdentifier),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ImageRepositoryType" Text -> ImageRepositoryType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ImageRepositoryType
imageRepositoryType)
          ]
      )