{-# 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.SSM.Types.DocumentRequires
-- 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.SSM.Types.DocumentRequires where

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

-- | An SSM document required by the current document.
--
-- /See:/ 'newDocumentRequires' smart constructor.
data DocumentRequires = DocumentRequires'
  { -- | The document version required by the current document.
    DocumentRequires -> Maybe Text
version :: Prelude.Maybe Prelude.Text,
    -- | The name of the required SSM document. The name can be an Amazon
    -- Resource Name (ARN).
    DocumentRequires -> Text
name :: Prelude.Text
  }
  deriving (DocumentRequires -> DocumentRequires -> Bool
(DocumentRequires -> DocumentRequires -> Bool)
-> (DocumentRequires -> DocumentRequires -> Bool)
-> Eq DocumentRequires
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DocumentRequires -> DocumentRequires -> Bool
$c/= :: DocumentRequires -> DocumentRequires -> Bool
== :: DocumentRequires -> DocumentRequires -> Bool
$c== :: DocumentRequires -> DocumentRequires -> Bool
Prelude.Eq, ReadPrec [DocumentRequires]
ReadPrec DocumentRequires
Int -> ReadS DocumentRequires
ReadS [DocumentRequires]
(Int -> ReadS DocumentRequires)
-> ReadS [DocumentRequires]
-> ReadPrec DocumentRequires
-> ReadPrec [DocumentRequires]
-> Read DocumentRequires
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DocumentRequires]
$creadListPrec :: ReadPrec [DocumentRequires]
readPrec :: ReadPrec DocumentRequires
$creadPrec :: ReadPrec DocumentRequires
readList :: ReadS [DocumentRequires]
$creadList :: ReadS [DocumentRequires]
readsPrec :: Int -> ReadS DocumentRequires
$creadsPrec :: Int -> ReadS DocumentRequires
Prelude.Read, Int -> DocumentRequires -> ShowS
[DocumentRequires] -> ShowS
DocumentRequires -> String
(Int -> DocumentRequires -> ShowS)
-> (DocumentRequires -> String)
-> ([DocumentRequires] -> ShowS)
-> Show DocumentRequires
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DocumentRequires] -> ShowS
$cshowList :: [DocumentRequires] -> ShowS
show :: DocumentRequires -> String
$cshow :: DocumentRequires -> String
showsPrec :: Int -> DocumentRequires -> ShowS
$cshowsPrec :: Int -> DocumentRequires -> ShowS
Prelude.Show, (forall x. DocumentRequires -> Rep DocumentRequires x)
-> (forall x. Rep DocumentRequires x -> DocumentRequires)
-> Generic DocumentRequires
forall x. Rep DocumentRequires x -> DocumentRequires
forall x. DocumentRequires -> Rep DocumentRequires x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DocumentRequires x -> DocumentRequires
$cfrom :: forall x. DocumentRequires -> Rep DocumentRequires x
Prelude.Generic)

-- |
-- Create a value of 'DocumentRequires' 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:
--
-- 'version', 'documentRequires_version' - The document version required by the current document.
--
-- 'name', 'documentRequires_name' - The name of the required SSM document. The name can be an Amazon
-- Resource Name (ARN).
newDocumentRequires ::
  -- | 'name'
  Prelude.Text ->
  DocumentRequires
newDocumentRequires :: Text -> DocumentRequires
newDocumentRequires Text
pName_ =
  DocumentRequires' :: Maybe Text -> Text -> DocumentRequires
DocumentRequires'
    { $sel:version:DocumentRequires' :: Maybe Text
version = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:DocumentRequires' :: Text
name = Text
pName_
    }

-- | The document version required by the current document.
documentRequires_version :: Lens.Lens' DocumentRequires (Prelude.Maybe Prelude.Text)
documentRequires_version :: (Maybe Text -> f (Maybe Text))
-> DocumentRequires -> f DocumentRequires
documentRequires_version = (DocumentRequires -> Maybe Text)
-> (DocumentRequires -> Maybe Text -> DocumentRequires)
-> Lens DocumentRequires DocumentRequires (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DocumentRequires' {Maybe Text
version :: Maybe Text
$sel:version:DocumentRequires' :: DocumentRequires -> Maybe Text
version} -> Maybe Text
version) (\s :: DocumentRequires
s@DocumentRequires' {} Maybe Text
a -> DocumentRequires
s {$sel:version:DocumentRequires' :: Maybe Text
version = Maybe Text
a} :: DocumentRequires)

-- | The name of the required SSM document. The name can be an Amazon
-- Resource Name (ARN).
documentRequires_name :: Lens.Lens' DocumentRequires Prelude.Text
documentRequires_name :: (Text -> f Text) -> DocumentRequires -> f DocumentRequires
documentRequires_name = (DocumentRequires -> Text)
-> (DocumentRequires -> Text -> DocumentRequires)
-> Lens DocumentRequires DocumentRequires Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DocumentRequires' {Text
name :: Text
$sel:name:DocumentRequires' :: DocumentRequires -> Text
name} -> Text
name) (\s :: DocumentRequires
s@DocumentRequires' {} Text
a -> DocumentRequires
s {$sel:name:DocumentRequires' :: Text
name = Text
a} :: DocumentRequires)

instance Core.FromJSON DocumentRequires where
  parseJSON :: Value -> Parser DocumentRequires
parseJSON =
    String
-> (Object -> Parser DocumentRequires)
-> Value
-> Parser DocumentRequires
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DocumentRequires"
      ( \Object
x ->
          Maybe Text -> Text -> DocumentRequires
DocumentRequires'
            (Maybe Text -> Text -> DocumentRequires)
-> Parser (Maybe Text) -> Parser (Text -> DocumentRequires)
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
"Version")
            Parser (Text -> DocumentRequires)
-> Parser Text -> Parser DocumentRequires
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
"Name")
      )

instance Prelude.Hashable DocumentRequires

instance Prelude.NFData DocumentRequires

instance Core.ToJSON DocumentRequires where
  toJSON :: DocumentRequires -> Value
toJSON DocumentRequires' {Maybe Text
Text
name :: Text
version :: Maybe Text
$sel:name:DocumentRequires' :: DocumentRequires -> Text
$sel:version:DocumentRequires' :: DocumentRequires -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Version" 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
version,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )