{-# 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.ECR.Types.ImageIdentifier
-- 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.ECR.Types.ImageIdentifier where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object with identifying information for an image in an Amazon ECR
-- repository.
--
-- /See:/ 'newImageIdentifier' smart constructor.
data ImageIdentifier = ImageIdentifier'
  { -- | The @sha256@ digest of the image manifest.
    ImageIdentifier -> Maybe Text
imageDigest :: Prelude.Maybe Prelude.Text,
    -- | The tag used for the image.
    ImageIdentifier -> Maybe Text
imageTag :: Prelude.Maybe Prelude.Text
  }
  deriving (ImageIdentifier -> ImageIdentifier -> Bool
(ImageIdentifier -> ImageIdentifier -> Bool)
-> (ImageIdentifier -> ImageIdentifier -> Bool)
-> Eq ImageIdentifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImageIdentifier -> ImageIdentifier -> Bool
$c/= :: ImageIdentifier -> ImageIdentifier -> Bool
== :: ImageIdentifier -> ImageIdentifier -> Bool
$c== :: ImageIdentifier -> ImageIdentifier -> Bool
Prelude.Eq, ReadPrec [ImageIdentifier]
ReadPrec ImageIdentifier
Int -> ReadS ImageIdentifier
ReadS [ImageIdentifier]
(Int -> ReadS ImageIdentifier)
-> ReadS [ImageIdentifier]
-> ReadPrec ImageIdentifier
-> ReadPrec [ImageIdentifier]
-> Read ImageIdentifier
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ImageIdentifier]
$creadListPrec :: ReadPrec [ImageIdentifier]
readPrec :: ReadPrec ImageIdentifier
$creadPrec :: ReadPrec ImageIdentifier
readList :: ReadS [ImageIdentifier]
$creadList :: ReadS [ImageIdentifier]
readsPrec :: Int -> ReadS ImageIdentifier
$creadsPrec :: Int -> ReadS ImageIdentifier
Prelude.Read, Int -> ImageIdentifier -> ShowS
[ImageIdentifier] -> ShowS
ImageIdentifier -> String
(Int -> ImageIdentifier -> ShowS)
-> (ImageIdentifier -> String)
-> ([ImageIdentifier] -> ShowS)
-> Show ImageIdentifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImageIdentifier] -> ShowS
$cshowList :: [ImageIdentifier] -> ShowS
show :: ImageIdentifier -> String
$cshow :: ImageIdentifier -> String
showsPrec :: Int -> ImageIdentifier -> ShowS
$cshowsPrec :: Int -> ImageIdentifier -> ShowS
Prelude.Show, (forall x. ImageIdentifier -> Rep ImageIdentifier x)
-> (forall x. Rep ImageIdentifier x -> ImageIdentifier)
-> Generic ImageIdentifier
forall x. Rep ImageIdentifier x -> ImageIdentifier
forall x. ImageIdentifier -> Rep ImageIdentifier x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ImageIdentifier x -> ImageIdentifier
$cfrom :: forall x. ImageIdentifier -> Rep ImageIdentifier x
Prelude.Generic)

-- |
-- Create a value of 'ImageIdentifier' 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:
--
-- 'imageDigest', 'imageIdentifier_imageDigest' - The @sha256@ digest of the image manifest.
--
-- 'imageTag', 'imageIdentifier_imageTag' - The tag used for the image.
newImageIdentifier ::
  ImageIdentifier
newImageIdentifier :: ImageIdentifier
newImageIdentifier =
  ImageIdentifier' :: Maybe Text -> Maybe Text -> ImageIdentifier
ImageIdentifier'
    { $sel:imageDigest:ImageIdentifier' :: Maybe Text
imageDigest = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:imageTag:ImageIdentifier' :: Maybe Text
imageTag = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The @sha256@ digest of the image manifest.
imageIdentifier_imageDigest :: Lens.Lens' ImageIdentifier (Prelude.Maybe Prelude.Text)
imageIdentifier_imageDigest :: (Maybe Text -> f (Maybe Text))
-> ImageIdentifier -> f ImageIdentifier
imageIdentifier_imageDigest = (ImageIdentifier -> Maybe Text)
-> (ImageIdentifier -> Maybe Text -> ImageIdentifier)
-> Lens ImageIdentifier ImageIdentifier (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageIdentifier' {Maybe Text
imageDigest :: Maybe Text
$sel:imageDigest:ImageIdentifier' :: ImageIdentifier -> Maybe Text
imageDigest} -> Maybe Text
imageDigest) (\s :: ImageIdentifier
s@ImageIdentifier' {} Maybe Text
a -> ImageIdentifier
s {$sel:imageDigest:ImageIdentifier' :: Maybe Text
imageDigest = Maybe Text
a} :: ImageIdentifier)

-- | The tag used for the image.
imageIdentifier_imageTag :: Lens.Lens' ImageIdentifier (Prelude.Maybe Prelude.Text)
imageIdentifier_imageTag :: (Maybe Text -> f (Maybe Text))
-> ImageIdentifier -> f ImageIdentifier
imageIdentifier_imageTag = (ImageIdentifier -> Maybe Text)
-> (ImageIdentifier -> Maybe Text -> ImageIdentifier)
-> Lens ImageIdentifier ImageIdentifier (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageIdentifier' {Maybe Text
imageTag :: Maybe Text
$sel:imageTag:ImageIdentifier' :: ImageIdentifier -> Maybe Text
imageTag} -> Maybe Text
imageTag) (\s :: ImageIdentifier
s@ImageIdentifier' {} Maybe Text
a -> ImageIdentifier
s {$sel:imageTag:ImageIdentifier' :: Maybe Text
imageTag = Maybe Text
a} :: ImageIdentifier)

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

instance Prelude.Hashable ImageIdentifier

instance Prelude.NFData ImageIdentifier

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