{-# 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.CodeArtifact.Types.PackageOriginRestrictions
-- 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.CodeArtifact.Types.PackageOriginRestrictions where

import Amazonka.CodeArtifact.Types.AllowPublish
import Amazonka.CodeArtifact.Types.AllowUpstream
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

-- | Details about the origin restrictions set on the package. The package
-- origin restrictions determine how new versions of a package can be added
-- to a specific repository.
--
-- /See:/ 'newPackageOriginRestrictions' smart constructor.
data PackageOriginRestrictions = PackageOriginRestrictions'
  { -- | The package origin configuration that determines if new versions of the
    -- package can be published directly to the repository.
    PackageOriginRestrictions -> AllowPublish
publish :: AllowPublish,
    -- | The package origin configuration that determines if new versions of the
    -- package can be added to the repository from an external connection or
    -- upstream source.
    PackageOriginRestrictions -> AllowUpstream
upstream :: AllowUpstream
  }
  deriving (PackageOriginRestrictions -> PackageOriginRestrictions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PackageOriginRestrictions -> PackageOriginRestrictions -> Bool
$c/= :: PackageOriginRestrictions -> PackageOriginRestrictions -> Bool
== :: PackageOriginRestrictions -> PackageOriginRestrictions -> Bool
$c== :: PackageOriginRestrictions -> PackageOriginRestrictions -> Bool
Prelude.Eq, ReadPrec [PackageOriginRestrictions]
ReadPrec PackageOriginRestrictions
Int -> ReadS PackageOriginRestrictions
ReadS [PackageOriginRestrictions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PackageOriginRestrictions]
$creadListPrec :: ReadPrec [PackageOriginRestrictions]
readPrec :: ReadPrec PackageOriginRestrictions
$creadPrec :: ReadPrec PackageOriginRestrictions
readList :: ReadS [PackageOriginRestrictions]
$creadList :: ReadS [PackageOriginRestrictions]
readsPrec :: Int -> ReadS PackageOriginRestrictions
$creadsPrec :: Int -> ReadS PackageOriginRestrictions
Prelude.Read, Int -> PackageOriginRestrictions -> ShowS
[PackageOriginRestrictions] -> ShowS
PackageOriginRestrictions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PackageOriginRestrictions] -> ShowS
$cshowList :: [PackageOriginRestrictions] -> ShowS
show :: PackageOriginRestrictions -> String
$cshow :: PackageOriginRestrictions -> String
showsPrec :: Int -> PackageOriginRestrictions -> ShowS
$cshowsPrec :: Int -> PackageOriginRestrictions -> ShowS
Prelude.Show, forall x.
Rep PackageOriginRestrictions x -> PackageOriginRestrictions
forall x.
PackageOriginRestrictions -> Rep PackageOriginRestrictions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PackageOriginRestrictions x -> PackageOriginRestrictions
$cfrom :: forall x.
PackageOriginRestrictions -> Rep PackageOriginRestrictions x
Prelude.Generic)

-- |
-- Create a value of 'PackageOriginRestrictions' 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:
--
-- 'publish', 'packageOriginRestrictions_publish' - The package origin configuration that determines if new versions of the
-- package can be published directly to the repository.
--
-- 'upstream', 'packageOriginRestrictions_upstream' - The package origin configuration that determines if new versions of the
-- package can be added to the repository from an external connection or
-- upstream source.
newPackageOriginRestrictions ::
  -- | 'publish'
  AllowPublish ->
  -- | 'upstream'
  AllowUpstream ->
  PackageOriginRestrictions
newPackageOriginRestrictions :: AllowPublish -> AllowUpstream -> PackageOriginRestrictions
newPackageOriginRestrictions AllowPublish
pPublish_ AllowUpstream
pUpstream_ =
  PackageOriginRestrictions'
    { $sel:publish:PackageOriginRestrictions' :: AllowPublish
publish = AllowPublish
pPublish_,
      $sel:upstream:PackageOriginRestrictions' :: AllowUpstream
upstream = AllowUpstream
pUpstream_
    }

-- | The package origin configuration that determines if new versions of the
-- package can be published directly to the repository.
packageOriginRestrictions_publish :: Lens.Lens' PackageOriginRestrictions AllowPublish
packageOriginRestrictions_publish :: Lens' PackageOriginRestrictions AllowPublish
packageOriginRestrictions_publish = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PackageOriginRestrictions' {AllowPublish
publish :: AllowPublish
$sel:publish:PackageOriginRestrictions' :: PackageOriginRestrictions -> AllowPublish
publish} -> AllowPublish
publish) (\s :: PackageOriginRestrictions
s@PackageOriginRestrictions' {} AllowPublish
a -> PackageOriginRestrictions
s {$sel:publish:PackageOriginRestrictions' :: AllowPublish
publish = AllowPublish
a} :: PackageOriginRestrictions)

-- | The package origin configuration that determines if new versions of the
-- package can be added to the repository from an external connection or
-- upstream source.
packageOriginRestrictions_upstream :: Lens.Lens' PackageOriginRestrictions AllowUpstream
packageOriginRestrictions_upstream :: Lens' PackageOriginRestrictions AllowUpstream
packageOriginRestrictions_upstream = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PackageOriginRestrictions' {AllowUpstream
upstream :: AllowUpstream
$sel:upstream:PackageOriginRestrictions' :: PackageOriginRestrictions -> AllowUpstream
upstream} -> AllowUpstream
upstream) (\s :: PackageOriginRestrictions
s@PackageOriginRestrictions' {} AllowUpstream
a -> PackageOriginRestrictions
s {$sel:upstream:PackageOriginRestrictions' :: AllowUpstream
upstream = AllowUpstream
a} :: PackageOriginRestrictions)

instance Data.FromJSON PackageOriginRestrictions where
  parseJSON :: Value -> Parser PackageOriginRestrictions
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PackageOriginRestrictions"
      ( \Object
x ->
          AllowPublish -> AllowUpstream -> PackageOriginRestrictions
PackageOriginRestrictions'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"publish")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"upstream")
      )

instance Prelude.Hashable PackageOriginRestrictions where
  hashWithSalt :: Int -> PackageOriginRestrictions -> Int
hashWithSalt Int
_salt PackageOriginRestrictions' {AllowPublish
AllowUpstream
upstream :: AllowUpstream
publish :: AllowPublish
$sel:upstream:PackageOriginRestrictions' :: PackageOriginRestrictions -> AllowUpstream
$sel:publish:PackageOriginRestrictions' :: PackageOriginRestrictions -> AllowPublish
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` AllowPublish
publish
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` AllowUpstream
upstream

instance Prelude.NFData PackageOriginRestrictions where
  rnf :: PackageOriginRestrictions -> ()
rnf PackageOriginRestrictions' {AllowPublish
AllowUpstream
upstream :: AllowUpstream
publish :: AllowPublish
$sel:upstream:PackageOriginRestrictions' :: PackageOriginRestrictions -> AllowUpstream
$sel:publish:PackageOriginRestrictions' :: PackageOriginRestrictions -> AllowPublish
..} =
    forall a. NFData a => a -> ()
Prelude.rnf AllowPublish
publish
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf AllowUpstream
upstream

instance Data.ToJSON PackageOriginRestrictions where
  toJSON :: PackageOriginRestrictions -> Value
toJSON PackageOriginRestrictions' {AllowPublish
AllowUpstream
upstream :: AllowUpstream
publish :: AllowPublish
$sel:upstream:PackageOriginRestrictions' :: PackageOriginRestrictions -> AllowUpstream
$sel:publish:PackageOriginRestrictions' :: PackageOriginRestrictions -> AllowPublish
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"publish" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= AllowPublish
publish),
            forall a. a -> Maybe a
Prelude.Just (Key
"upstream" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= AllowUpstream
upstream)
          ]
      )