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

import qualified Amazonka.Core as Core
import Amazonka.ECR.Types.ReplicationRule
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The replication configuration for a registry.
--
-- /See:/ 'newReplicationConfiguration' smart constructor.
data ReplicationConfiguration = ReplicationConfiguration'
  { -- | An array of objects representing the replication destinations and
    -- repository filters for a replication configuration.
    ReplicationConfiguration -> [ReplicationRule]
rules :: [ReplicationRule]
  }
  deriving (ReplicationConfiguration -> ReplicationConfiguration -> Bool
(ReplicationConfiguration -> ReplicationConfiguration -> Bool)
-> (ReplicationConfiguration -> ReplicationConfiguration -> Bool)
-> Eq ReplicationConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReplicationConfiguration -> ReplicationConfiguration -> Bool
$c/= :: ReplicationConfiguration -> ReplicationConfiguration -> Bool
== :: ReplicationConfiguration -> ReplicationConfiguration -> Bool
$c== :: ReplicationConfiguration -> ReplicationConfiguration -> Bool
Prelude.Eq, ReadPrec [ReplicationConfiguration]
ReadPrec ReplicationConfiguration
Int -> ReadS ReplicationConfiguration
ReadS [ReplicationConfiguration]
(Int -> ReadS ReplicationConfiguration)
-> ReadS [ReplicationConfiguration]
-> ReadPrec ReplicationConfiguration
-> ReadPrec [ReplicationConfiguration]
-> Read ReplicationConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReplicationConfiguration]
$creadListPrec :: ReadPrec [ReplicationConfiguration]
readPrec :: ReadPrec ReplicationConfiguration
$creadPrec :: ReadPrec ReplicationConfiguration
readList :: ReadS [ReplicationConfiguration]
$creadList :: ReadS [ReplicationConfiguration]
readsPrec :: Int -> ReadS ReplicationConfiguration
$creadsPrec :: Int -> ReadS ReplicationConfiguration
Prelude.Read, Int -> ReplicationConfiguration -> ShowS
[ReplicationConfiguration] -> ShowS
ReplicationConfiguration -> String
(Int -> ReplicationConfiguration -> ShowS)
-> (ReplicationConfiguration -> String)
-> ([ReplicationConfiguration] -> ShowS)
-> Show ReplicationConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReplicationConfiguration] -> ShowS
$cshowList :: [ReplicationConfiguration] -> ShowS
show :: ReplicationConfiguration -> String
$cshow :: ReplicationConfiguration -> String
showsPrec :: Int -> ReplicationConfiguration -> ShowS
$cshowsPrec :: Int -> ReplicationConfiguration -> ShowS
Prelude.Show, (forall x.
 ReplicationConfiguration -> Rep ReplicationConfiguration x)
-> (forall x.
    Rep ReplicationConfiguration x -> ReplicationConfiguration)
-> Generic ReplicationConfiguration
forall x.
Rep ReplicationConfiguration x -> ReplicationConfiguration
forall x.
ReplicationConfiguration -> Rep ReplicationConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ReplicationConfiguration x -> ReplicationConfiguration
$cfrom :: forall x.
ReplicationConfiguration -> Rep ReplicationConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ReplicationConfiguration' 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:
--
-- 'rules', 'replicationConfiguration_rules' - An array of objects representing the replication destinations and
-- repository filters for a replication configuration.
newReplicationConfiguration ::
  ReplicationConfiguration
newReplicationConfiguration :: ReplicationConfiguration
newReplicationConfiguration =
  ReplicationConfiguration' :: [ReplicationRule] -> ReplicationConfiguration
ReplicationConfiguration' {$sel:rules:ReplicationConfiguration' :: [ReplicationRule]
rules = [ReplicationRule]
forall a. Monoid a => a
Prelude.mempty}

-- | An array of objects representing the replication destinations and
-- repository filters for a replication configuration.
replicationConfiguration_rules :: Lens.Lens' ReplicationConfiguration [ReplicationRule]
replicationConfiguration_rules :: ([ReplicationRule] -> f [ReplicationRule])
-> ReplicationConfiguration -> f ReplicationConfiguration
replicationConfiguration_rules = (ReplicationConfiguration -> [ReplicationRule])
-> (ReplicationConfiguration
    -> [ReplicationRule] -> ReplicationConfiguration)
-> Lens
     ReplicationConfiguration
     ReplicationConfiguration
     [ReplicationRule]
     [ReplicationRule]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReplicationConfiguration' {[ReplicationRule]
rules :: [ReplicationRule]
$sel:rules:ReplicationConfiguration' :: ReplicationConfiguration -> [ReplicationRule]
rules} -> [ReplicationRule]
rules) (\s :: ReplicationConfiguration
s@ReplicationConfiguration' {} [ReplicationRule]
a -> ReplicationConfiguration
s {$sel:rules:ReplicationConfiguration' :: [ReplicationRule]
rules = [ReplicationRule]
a} :: ReplicationConfiguration) (([ReplicationRule] -> f [ReplicationRule])
 -> ReplicationConfiguration -> f ReplicationConfiguration)
-> (([ReplicationRule] -> f [ReplicationRule])
    -> [ReplicationRule] -> f [ReplicationRule])
-> ([ReplicationRule] -> f [ReplicationRule])
-> ReplicationConfiguration
-> f ReplicationConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([ReplicationRule] -> f [ReplicationRule])
-> [ReplicationRule] -> f [ReplicationRule]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable ReplicationConfiguration

instance Prelude.NFData ReplicationConfiguration

instance Core.ToJSON ReplicationConfiguration where
  toJSON :: ReplicationConfiguration -> Value
toJSON ReplicationConfiguration' {[ReplicationRule]
rules :: [ReplicationRule]
$sel:rules:ReplicationConfiguration' :: ReplicationConfiguration -> [ReplicationRule]
..} =
    [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
"rules" Text -> [ReplicationRule] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [ReplicationRule]
rules)]
      )