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

import qualified Amazonka.Core as Core
import Amazonka.ECR.Types.ReplicationDestination
import Amazonka.ECR.Types.RepositoryFilter
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An array of objects representing the replication destinations and
-- repository filters for a replication configuration.
--
-- /See:/ 'newReplicationRule' smart constructor.
data ReplicationRule = ReplicationRule'
  { -- | An array of objects representing the filters for a replication rule.
    -- Specifying a repository filter for a replication rule provides a method
    -- for controlling which repositories in a private registry are replicated.
    ReplicationRule -> Maybe (NonEmpty RepositoryFilter)
repositoryFilters :: Prelude.Maybe (Prelude.NonEmpty RepositoryFilter),
    -- | An array of objects representing the destination for a replication rule.
    ReplicationRule -> [ReplicationDestination]
destinations :: [ReplicationDestination]
  }
  deriving (ReplicationRule -> ReplicationRule -> Bool
(ReplicationRule -> ReplicationRule -> Bool)
-> (ReplicationRule -> ReplicationRule -> Bool)
-> Eq ReplicationRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReplicationRule -> ReplicationRule -> Bool
$c/= :: ReplicationRule -> ReplicationRule -> Bool
== :: ReplicationRule -> ReplicationRule -> Bool
$c== :: ReplicationRule -> ReplicationRule -> Bool
Prelude.Eq, ReadPrec [ReplicationRule]
ReadPrec ReplicationRule
Int -> ReadS ReplicationRule
ReadS [ReplicationRule]
(Int -> ReadS ReplicationRule)
-> ReadS [ReplicationRule]
-> ReadPrec ReplicationRule
-> ReadPrec [ReplicationRule]
-> Read ReplicationRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReplicationRule]
$creadListPrec :: ReadPrec [ReplicationRule]
readPrec :: ReadPrec ReplicationRule
$creadPrec :: ReadPrec ReplicationRule
readList :: ReadS [ReplicationRule]
$creadList :: ReadS [ReplicationRule]
readsPrec :: Int -> ReadS ReplicationRule
$creadsPrec :: Int -> ReadS ReplicationRule
Prelude.Read, Int -> ReplicationRule -> ShowS
[ReplicationRule] -> ShowS
ReplicationRule -> String
(Int -> ReplicationRule -> ShowS)
-> (ReplicationRule -> String)
-> ([ReplicationRule] -> ShowS)
-> Show ReplicationRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReplicationRule] -> ShowS
$cshowList :: [ReplicationRule] -> ShowS
show :: ReplicationRule -> String
$cshow :: ReplicationRule -> String
showsPrec :: Int -> ReplicationRule -> ShowS
$cshowsPrec :: Int -> ReplicationRule -> ShowS
Prelude.Show, (forall x. ReplicationRule -> Rep ReplicationRule x)
-> (forall x. Rep ReplicationRule x -> ReplicationRule)
-> Generic ReplicationRule
forall x. Rep ReplicationRule x -> ReplicationRule
forall x. ReplicationRule -> Rep ReplicationRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReplicationRule x -> ReplicationRule
$cfrom :: forall x. ReplicationRule -> Rep ReplicationRule x
Prelude.Generic)

-- |
-- Create a value of 'ReplicationRule' 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:
--
-- 'repositoryFilters', 'replicationRule_repositoryFilters' - An array of objects representing the filters for a replication rule.
-- Specifying a repository filter for a replication rule provides a method
-- for controlling which repositories in a private registry are replicated.
--
-- 'destinations', 'replicationRule_destinations' - An array of objects representing the destination for a replication rule.
newReplicationRule ::
  ReplicationRule
newReplicationRule :: ReplicationRule
newReplicationRule =
  ReplicationRule' :: Maybe (NonEmpty RepositoryFilter)
-> [ReplicationDestination] -> ReplicationRule
ReplicationRule'
    { $sel:repositoryFilters:ReplicationRule' :: Maybe (NonEmpty RepositoryFilter)
repositoryFilters =
        Maybe (NonEmpty RepositoryFilter)
forall a. Maybe a
Prelude.Nothing,
      $sel:destinations:ReplicationRule' :: [ReplicationDestination]
destinations = [ReplicationDestination]
forall a. Monoid a => a
Prelude.mempty
    }

-- | An array of objects representing the filters for a replication rule.
-- Specifying a repository filter for a replication rule provides a method
-- for controlling which repositories in a private registry are replicated.
replicationRule_repositoryFilters :: Lens.Lens' ReplicationRule (Prelude.Maybe (Prelude.NonEmpty RepositoryFilter))
replicationRule_repositoryFilters :: (Maybe (NonEmpty RepositoryFilter)
 -> f (Maybe (NonEmpty RepositoryFilter)))
-> ReplicationRule -> f ReplicationRule
replicationRule_repositoryFilters = (ReplicationRule -> Maybe (NonEmpty RepositoryFilter))
-> (ReplicationRule
    -> Maybe (NonEmpty RepositoryFilter) -> ReplicationRule)
-> Lens
     ReplicationRule
     ReplicationRule
     (Maybe (NonEmpty RepositoryFilter))
     (Maybe (NonEmpty RepositoryFilter))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReplicationRule' {Maybe (NonEmpty RepositoryFilter)
repositoryFilters :: Maybe (NonEmpty RepositoryFilter)
$sel:repositoryFilters:ReplicationRule' :: ReplicationRule -> Maybe (NonEmpty RepositoryFilter)
repositoryFilters} -> Maybe (NonEmpty RepositoryFilter)
repositoryFilters) (\s :: ReplicationRule
s@ReplicationRule' {} Maybe (NonEmpty RepositoryFilter)
a -> ReplicationRule
s {$sel:repositoryFilters:ReplicationRule' :: Maybe (NonEmpty RepositoryFilter)
repositoryFilters = Maybe (NonEmpty RepositoryFilter)
a} :: ReplicationRule) ((Maybe (NonEmpty RepositoryFilter)
  -> f (Maybe (NonEmpty RepositoryFilter)))
 -> ReplicationRule -> f ReplicationRule)
-> ((Maybe (NonEmpty RepositoryFilter)
     -> f (Maybe (NonEmpty RepositoryFilter)))
    -> Maybe (NonEmpty RepositoryFilter)
    -> f (Maybe (NonEmpty RepositoryFilter)))
-> (Maybe (NonEmpty RepositoryFilter)
    -> f (Maybe (NonEmpty RepositoryFilter)))
-> ReplicationRule
-> f ReplicationRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty RepositoryFilter)
  (NonEmpty RepositoryFilter)
  (NonEmpty RepositoryFilter)
  (NonEmpty RepositoryFilter)
-> Iso
     (Maybe (NonEmpty RepositoryFilter))
     (Maybe (NonEmpty RepositoryFilter))
     (Maybe (NonEmpty RepositoryFilter))
     (Maybe (NonEmpty RepositoryFilter))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty RepositoryFilter)
  (NonEmpty RepositoryFilter)
  (NonEmpty RepositoryFilter)
  (NonEmpty RepositoryFilter)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | An array of objects representing the destination for a replication rule.
replicationRule_destinations :: Lens.Lens' ReplicationRule [ReplicationDestination]
replicationRule_destinations :: ([ReplicationDestination] -> f [ReplicationDestination])
-> ReplicationRule -> f ReplicationRule
replicationRule_destinations = (ReplicationRule -> [ReplicationDestination])
-> (ReplicationRule -> [ReplicationDestination] -> ReplicationRule)
-> Lens
     ReplicationRule
     ReplicationRule
     [ReplicationDestination]
     [ReplicationDestination]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReplicationRule' {[ReplicationDestination]
destinations :: [ReplicationDestination]
$sel:destinations:ReplicationRule' :: ReplicationRule -> [ReplicationDestination]
destinations} -> [ReplicationDestination]
destinations) (\s :: ReplicationRule
s@ReplicationRule' {} [ReplicationDestination]
a -> ReplicationRule
s {$sel:destinations:ReplicationRule' :: [ReplicationDestination]
destinations = [ReplicationDestination]
a} :: ReplicationRule) (([ReplicationDestination] -> f [ReplicationDestination])
 -> ReplicationRule -> f ReplicationRule)
-> (([ReplicationDestination] -> f [ReplicationDestination])
    -> [ReplicationDestination] -> f [ReplicationDestination])
-> ([ReplicationDestination] -> f [ReplicationDestination])
-> ReplicationRule
-> f ReplicationRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([ReplicationDestination] -> f [ReplicationDestination])
-> [ReplicationDestination] -> f [ReplicationDestination]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable ReplicationRule

instance Prelude.NFData ReplicationRule

instance Core.ToJSON ReplicationRule where
  toJSON :: ReplicationRule -> Value
toJSON ReplicationRule' {[ReplicationDestination]
Maybe (NonEmpty RepositoryFilter)
destinations :: [ReplicationDestination]
repositoryFilters :: Maybe (NonEmpty RepositoryFilter)
$sel:destinations:ReplicationRule' :: ReplicationRule -> [ReplicationDestination]
$sel:repositoryFilters:ReplicationRule' :: ReplicationRule -> Maybe (NonEmpty RepositoryFilter)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"repositoryFilters" Text -> NonEmpty RepositoryFilter -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty RepositoryFilter -> Pair)
-> Maybe (NonEmpty RepositoryFilter) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty RepositoryFilter)
repositoryFilters,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"destinations" Text -> [ReplicationDestination] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [ReplicationDestination]
destinations)
          ]
      )