{-# 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.PatchRuleGroup
-- 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.PatchRuleGroup where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SSM.Types.PatchRule

-- | A set of rules defining the approval rules for a patch baseline.
--
-- /See:/ 'newPatchRuleGroup' smart constructor.
data PatchRuleGroup = PatchRuleGroup'
  { -- | The rules that make up the rule group.
    PatchRuleGroup -> [PatchRule]
patchRules :: [PatchRule]
  }
  deriving (PatchRuleGroup -> PatchRuleGroup -> Bool
(PatchRuleGroup -> PatchRuleGroup -> Bool)
-> (PatchRuleGroup -> PatchRuleGroup -> Bool) -> Eq PatchRuleGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PatchRuleGroup -> PatchRuleGroup -> Bool
$c/= :: PatchRuleGroup -> PatchRuleGroup -> Bool
== :: PatchRuleGroup -> PatchRuleGroup -> Bool
$c== :: PatchRuleGroup -> PatchRuleGroup -> Bool
Prelude.Eq, ReadPrec [PatchRuleGroup]
ReadPrec PatchRuleGroup
Int -> ReadS PatchRuleGroup
ReadS [PatchRuleGroup]
(Int -> ReadS PatchRuleGroup)
-> ReadS [PatchRuleGroup]
-> ReadPrec PatchRuleGroup
-> ReadPrec [PatchRuleGroup]
-> Read PatchRuleGroup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PatchRuleGroup]
$creadListPrec :: ReadPrec [PatchRuleGroup]
readPrec :: ReadPrec PatchRuleGroup
$creadPrec :: ReadPrec PatchRuleGroup
readList :: ReadS [PatchRuleGroup]
$creadList :: ReadS [PatchRuleGroup]
readsPrec :: Int -> ReadS PatchRuleGroup
$creadsPrec :: Int -> ReadS PatchRuleGroup
Prelude.Read, Int -> PatchRuleGroup -> ShowS
[PatchRuleGroup] -> ShowS
PatchRuleGroup -> String
(Int -> PatchRuleGroup -> ShowS)
-> (PatchRuleGroup -> String)
-> ([PatchRuleGroup] -> ShowS)
-> Show PatchRuleGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PatchRuleGroup] -> ShowS
$cshowList :: [PatchRuleGroup] -> ShowS
show :: PatchRuleGroup -> String
$cshow :: PatchRuleGroup -> String
showsPrec :: Int -> PatchRuleGroup -> ShowS
$cshowsPrec :: Int -> PatchRuleGroup -> ShowS
Prelude.Show, (forall x. PatchRuleGroup -> Rep PatchRuleGroup x)
-> (forall x. Rep PatchRuleGroup x -> PatchRuleGroup)
-> Generic PatchRuleGroup
forall x. Rep PatchRuleGroup x -> PatchRuleGroup
forall x. PatchRuleGroup -> Rep PatchRuleGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PatchRuleGroup x -> PatchRuleGroup
$cfrom :: forall x. PatchRuleGroup -> Rep PatchRuleGroup x
Prelude.Generic)

-- |
-- Create a value of 'PatchRuleGroup' 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:
--
-- 'patchRules', 'patchRuleGroup_patchRules' - The rules that make up the rule group.
newPatchRuleGroup ::
  PatchRuleGroup
newPatchRuleGroup :: PatchRuleGroup
newPatchRuleGroup =
  PatchRuleGroup' :: [PatchRule] -> PatchRuleGroup
PatchRuleGroup' {$sel:patchRules:PatchRuleGroup' :: [PatchRule]
patchRules = [PatchRule]
forall a. Monoid a => a
Prelude.mempty}

-- | The rules that make up the rule group.
patchRuleGroup_patchRules :: Lens.Lens' PatchRuleGroup [PatchRule]
patchRuleGroup_patchRules :: ([PatchRule] -> f [PatchRule])
-> PatchRuleGroup -> f PatchRuleGroup
patchRuleGroup_patchRules = (PatchRuleGroup -> [PatchRule])
-> (PatchRuleGroup -> [PatchRule] -> PatchRuleGroup)
-> Lens PatchRuleGroup PatchRuleGroup [PatchRule] [PatchRule]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PatchRuleGroup' {[PatchRule]
patchRules :: [PatchRule]
$sel:patchRules:PatchRuleGroup' :: PatchRuleGroup -> [PatchRule]
patchRules} -> [PatchRule]
patchRules) (\s :: PatchRuleGroup
s@PatchRuleGroup' {} [PatchRule]
a -> PatchRuleGroup
s {$sel:patchRules:PatchRuleGroup' :: [PatchRule]
patchRules = [PatchRule]
a} :: PatchRuleGroup) (([PatchRule] -> f [PatchRule])
 -> PatchRuleGroup -> f PatchRuleGroup)
-> (([PatchRule] -> f [PatchRule]) -> [PatchRule] -> f [PatchRule])
-> ([PatchRule] -> f [PatchRule])
-> PatchRuleGroup
-> f PatchRuleGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([PatchRule] -> f [PatchRule]) -> [PatchRule] -> f [PatchRule]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON PatchRuleGroup where
  parseJSON :: Value -> Parser PatchRuleGroup
parseJSON =
    String
-> (Object -> Parser PatchRuleGroup)
-> Value
-> Parser PatchRuleGroup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PatchRuleGroup"
      ( \Object
x ->
          [PatchRule] -> PatchRuleGroup
PatchRuleGroup'
            ([PatchRule] -> PatchRuleGroup)
-> Parser [PatchRule] -> Parser PatchRuleGroup
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe [PatchRule])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PatchRules" Parser (Maybe [PatchRule]) -> [PatchRule] -> Parser [PatchRule]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [PatchRule]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable PatchRuleGroup

instance Prelude.NFData PatchRuleGroup

instance Core.ToJSON PatchRuleGroup where
  toJSON :: PatchRuleGroup -> Value
toJSON PatchRuleGroup' {[PatchRule]
patchRules :: [PatchRule]
$sel:patchRules:PatchRuleGroup' :: PatchRuleGroup -> [PatchRule]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"PatchRules" Text -> [PatchRule] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [PatchRule]
patchRules)]
      )