{-# 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.CodeDeploy.Types.AppSpecContent
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CodeDeploy.Types.AppSpecContent where

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

-- | A revision for an Lambda or Amazon ECS deployment that is a
-- YAML-formatted or JSON-formatted string. For Lambda and Amazon ECS
-- deployments, the revision is the same as the AppSpec file. This method
-- replaces the deprecated @RawString@ data type.
--
-- /See:/ 'newAppSpecContent' smart constructor.
data AppSpecContent = AppSpecContent'
  { -- | The YAML-formatted or JSON-formatted revision string.
    --
    -- For an Lambda deployment, the content includes a Lambda function name,
    -- the alias for its original version, and the alias for its replacement
    -- version. The deployment shifts traffic from the original version of the
    -- Lambda function to the replacement version.
    --
    -- For an Amazon ECS deployment, the content includes the task name,
    -- information about the load balancer that serves traffic to the
    -- container, and more.
    --
    -- For both types of deployments, the content can specify Lambda functions
    -- that run at specified hooks, such as @BeforeInstall@, during a
    -- deployment.
    AppSpecContent -> Maybe Text
content :: Prelude.Maybe Prelude.Text,
    -- | The SHA256 hash value of the revision content.
    AppSpecContent -> Maybe Text
sha256 :: Prelude.Maybe Prelude.Text
  }
  deriving (AppSpecContent -> AppSpecContent -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AppSpecContent -> AppSpecContent -> Bool
$c/= :: AppSpecContent -> AppSpecContent -> Bool
== :: AppSpecContent -> AppSpecContent -> Bool
$c== :: AppSpecContent -> AppSpecContent -> Bool
Prelude.Eq, ReadPrec [AppSpecContent]
ReadPrec AppSpecContent
Int -> ReadS AppSpecContent
ReadS [AppSpecContent]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AppSpecContent]
$creadListPrec :: ReadPrec [AppSpecContent]
readPrec :: ReadPrec AppSpecContent
$creadPrec :: ReadPrec AppSpecContent
readList :: ReadS [AppSpecContent]
$creadList :: ReadS [AppSpecContent]
readsPrec :: Int -> ReadS AppSpecContent
$creadsPrec :: Int -> ReadS AppSpecContent
Prelude.Read, Int -> AppSpecContent -> ShowS
[AppSpecContent] -> ShowS
AppSpecContent -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AppSpecContent] -> ShowS
$cshowList :: [AppSpecContent] -> ShowS
show :: AppSpecContent -> String
$cshow :: AppSpecContent -> String
showsPrec :: Int -> AppSpecContent -> ShowS
$cshowsPrec :: Int -> AppSpecContent -> ShowS
Prelude.Show, forall x. Rep AppSpecContent x -> AppSpecContent
forall x. AppSpecContent -> Rep AppSpecContent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AppSpecContent x -> AppSpecContent
$cfrom :: forall x. AppSpecContent -> Rep AppSpecContent x
Prelude.Generic)

-- |
-- Create a value of 'AppSpecContent' 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:
--
-- 'content', 'appSpecContent_content' - The YAML-formatted or JSON-formatted revision string.
--
-- For an Lambda deployment, the content includes a Lambda function name,
-- the alias for its original version, and the alias for its replacement
-- version. The deployment shifts traffic from the original version of the
-- Lambda function to the replacement version.
--
-- For an Amazon ECS deployment, the content includes the task name,
-- information about the load balancer that serves traffic to the
-- container, and more.
--
-- For both types of deployments, the content can specify Lambda functions
-- that run at specified hooks, such as @BeforeInstall@, during a
-- deployment.
--
-- 'sha256', 'appSpecContent_sha256' - The SHA256 hash value of the revision content.
newAppSpecContent ::
  AppSpecContent
newAppSpecContent :: AppSpecContent
newAppSpecContent =
  AppSpecContent'
    { $sel:content:AppSpecContent' :: Maybe Text
content = forall a. Maybe a
Prelude.Nothing,
      $sel:sha256:AppSpecContent' :: Maybe Text
sha256 = forall a. Maybe a
Prelude.Nothing
    }

-- | The YAML-formatted or JSON-formatted revision string.
--
-- For an Lambda deployment, the content includes a Lambda function name,
-- the alias for its original version, and the alias for its replacement
-- version. The deployment shifts traffic from the original version of the
-- Lambda function to the replacement version.
--
-- For an Amazon ECS deployment, the content includes the task name,
-- information about the load balancer that serves traffic to the
-- container, and more.
--
-- For both types of deployments, the content can specify Lambda functions
-- that run at specified hooks, such as @BeforeInstall@, during a
-- deployment.
appSpecContent_content :: Lens.Lens' AppSpecContent (Prelude.Maybe Prelude.Text)
appSpecContent_content :: Lens' AppSpecContent (Maybe Text)
appSpecContent_content = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AppSpecContent' {Maybe Text
content :: Maybe Text
$sel:content:AppSpecContent' :: AppSpecContent -> Maybe Text
content} -> Maybe Text
content) (\s :: AppSpecContent
s@AppSpecContent' {} Maybe Text
a -> AppSpecContent
s {$sel:content:AppSpecContent' :: Maybe Text
content = Maybe Text
a} :: AppSpecContent)

-- | The SHA256 hash value of the revision content.
appSpecContent_sha256 :: Lens.Lens' AppSpecContent (Prelude.Maybe Prelude.Text)
appSpecContent_sha256 :: Lens' AppSpecContent (Maybe Text)
appSpecContent_sha256 = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AppSpecContent' {Maybe Text
sha256 :: Maybe Text
$sel:sha256:AppSpecContent' :: AppSpecContent -> Maybe Text
sha256} -> Maybe Text
sha256) (\s :: AppSpecContent
s@AppSpecContent' {} Maybe Text
a -> AppSpecContent
s {$sel:sha256:AppSpecContent' :: Maybe Text
sha256 = Maybe Text
a} :: AppSpecContent)

instance Data.FromJSON AppSpecContent where
  parseJSON :: Value -> Parser AppSpecContent
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AppSpecContent"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> AppSpecContent
AppSpecContent'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"content")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"sha256")
      )

instance Prelude.Hashable AppSpecContent where
  hashWithSalt :: Int -> AppSpecContent -> Int
hashWithSalt Int
_salt AppSpecContent' {Maybe Text
sha256 :: Maybe Text
content :: Maybe Text
$sel:sha256:AppSpecContent' :: AppSpecContent -> Maybe Text
$sel:content:AppSpecContent' :: AppSpecContent -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
content
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sha256

instance Prelude.NFData AppSpecContent where
  rnf :: AppSpecContent -> ()
rnf AppSpecContent' {Maybe Text
sha256 :: Maybe Text
content :: Maybe Text
$sel:sha256:AppSpecContent' :: AppSpecContent -> Maybe Text
$sel:content:AppSpecContent' :: AppSpecContent -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
content
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
sha256

instance Data.ToJSON AppSpecContent where
  toJSON :: AppSpecContent -> Value
toJSON AppSpecContent' {Maybe Text
sha256 :: Maybe Text
content :: Maybe Text
$sel:sha256:AppSpecContent' :: AppSpecContent -> Maybe Text
$sel:content:AppSpecContent' :: AppSpecContent -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"content" 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 Text
content,
            (Key
"sha256" 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 Text
sha256
          ]
      )