{-# 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.MediaPackage.Types.EncryptionContractConfiguration
-- 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.MediaPackage.Types.EncryptionContractConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MediaPackage.Types.PresetSpeke20Audio
import Amazonka.MediaPackage.Types.PresetSpeke20Video
import qualified Amazonka.Prelude as Prelude

-- | Use encryptionContractConfiguration to configure one or more content
-- encryption keys for your endpoints that use SPEKE 2.0. The encryption
-- contract defines which content keys are used to encrypt the audio and
-- video tracks in your stream. To configure the encryption contract,
-- specify which audio and video encryption presets to use. Note the
-- following considerations when using encryptionContractConfiguration:
-- encryptionContractConfiguration can be used for DASH or CMAF endpoints
-- that use SPEKE 2.0. SPEKE 2.0 relies on the CPIX 2.3 specification. You
-- must disable key rotation for this endpoint by setting
-- keyRotationIntervalSeconds to 0.
--
-- /See:/ 'newEncryptionContractConfiguration' smart constructor.
data EncryptionContractConfiguration = EncryptionContractConfiguration'
  { -- | A collection of audio encryption presets.
    EncryptionContractConfiguration -> PresetSpeke20Audio
presetSpeke20Audio :: PresetSpeke20Audio,
    -- | A collection of video encryption presets.
    EncryptionContractConfiguration -> PresetSpeke20Video
presetSpeke20Video :: PresetSpeke20Video
  }
  deriving (EncryptionContractConfiguration
-> EncryptionContractConfiguration -> Bool
(EncryptionContractConfiguration
 -> EncryptionContractConfiguration -> Bool)
-> (EncryptionContractConfiguration
    -> EncryptionContractConfiguration -> Bool)
-> Eq EncryptionContractConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EncryptionContractConfiguration
-> EncryptionContractConfiguration -> Bool
$c/= :: EncryptionContractConfiguration
-> EncryptionContractConfiguration -> Bool
== :: EncryptionContractConfiguration
-> EncryptionContractConfiguration -> Bool
$c== :: EncryptionContractConfiguration
-> EncryptionContractConfiguration -> Bool
Prelude.Eq, ReadPrec [EncryptionContractConfiguration]
ReadPrec EncryptionContractConfiguration
Int -> ReadS EncryptionContractConfiguration
ReadS [EncryptionContractConfiguration]
(Int -> ReadS EncryptionContractConfiguration)
-> ReadS [EncryptionContractConfiguration]
-> ReadPrec EncryptionContractConfiguration
-> ReadPrec [EncryptionContractConfiguration]
-> Read EncryptionContractConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EncryptionContractConfiguration]
$creadListPrec :: ReadPrec [EncryptionContractConfiguration]
readPrec :: ReadPrec EncryptionContractConfiguration
$creadPrec :: ReadPrec EncryptionContractConfiguration
readList :: ReadS [EncryptionContractConfiguration]
$creadList :: ReadS [EncryptionContractConfiguration]
readsPrec :: Int -> ReadS EncryptionContractConfiguration
$creadsPrec :: Int -> ReadS EncryptionContractConfiguration
Prelude.Read, Int -> EncryptionContractConfiguration -> ShowS
[EncryptionContractConfiguration] -> ShowS
EncryptionContractConfiguration -> String
(Int -> EncryptionContractConfiguration -> ShowS)
-> (EncryptionContractConfiguration -> String)
-> ([EncryptionContractConfiguration] -> ShowS)
-> Show EncryptionContractConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EncryptionContractConfiguration] -> ShowS
$cshowList :: [EncryptionContractConfiguration] -> ShowS
show :: EncryptionContractConfiguration -> String
$cshow :: EncryptionContractConfiguration -> String
showsPrec :: Int -> EncryptionContractConfiguration -> ShowS
$cshowsPrec :: Int -> EncryptionContractConfiguration -> ShowS
Prelude.Show, (forall x.
 EncryptionContractConfiguration
 -> Rep EncryptionContractConfiguration x)
-> (forall x.
    Rep EncryptionContractConfiguration x
    -> EncryptionContractConfiguration)
-> Generic EncryptionContractConfiguration
forall x.
Rep EncryptionContractConfiguration x
-> EncryptionContractConfiguration
forall x.
EncryptionContractConfiguration
-> Rep EncryptionContractConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep EncryptionContractConfiguration x
-> EncryptionContractConfiguration
$cfrom :: forall x.
EncryptionContractConfiguration
-> Rep EncryptionContractConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'EncryptionContractConfiguration' 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:
--
-- 'presetSpeke20Audio', 'encryptionContractConfiguration_presetSpeke20Audio' - A collection of audio encryption presets.
--
-- 'presetSpeke20Video', 'encryptionContractConfiguration_presetSpeke20Video' - A collection of video encryption presets.
newEncryptionContractConfiguration ::
  -- | 'presetSpeke20Audio'
  PresetSpeke20Audio ->
  -- | 'presetSpeke20Video'
  PresetSpeke20Video ->
  EncryptionContractConfiguration
newEncryptionContractConfiguration :: PresetSpeke20Audio
-> PresetSpeke20Video -> EncryptionContractConfiguration
newEncryptionContractConfiguration
  PresetSpeke20Audio
pPresetSpeke20Audio_
  PresetSpeke20Video
pPresetSpeke20Video_ =
    EncryptionContractConfiguration' :: PresetSpeke20Audio
-> PresetSpeke20Video -> EncryptionContractConfiguration
EncryptionContractConfiguration'
      { $sel:presetSpeke20Audio:EncryptionContractConfiguration' :: PresetSpeke20Audio
presetSpeke20Audio =
          PresetSpeke20Audio
pPresetSpeke20Audio_,
        $sel:presetSpeke20Video:EncryptionContractConfiguration' :: PresetSpeke20Video
presetSpeke20Video = PresetSpeke20Video
pPresetSpeke20Video_
      }

-- | A collection of audio encryption presets.
encryptionContractConfiguration_presetSpeke20Audio :: Lens.Lens' EncryptionContractConfiguration PresetSpeke20Audio
encryptionContractConfiguration_presetSpeke20Audio :: (PresetSpeke20Audio -> f PresetSpeke20Audio)
-> EncryptionContractConfiguration
-> f EncryptionContractConfiguration
encryptionContractConfiguration_presetSpeke20Audio = (EncryptionContractConfiguration -> PresetSpeke20Audio)
-> (EncryptionContractConfiguration
    -> PresetSpeke20Audio -> EncryptionContractConfiguration)
-> Lens
     EncryptionContractConfiguration
     EncryptionContractConfiguration
     PresetSpeke20Audio
     PresetSpeke20Audio
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionContractConfiguration' {PresetSpeke20Audio
presetSpeke20Audio :: PresetSpeke20Audio
$sel:presetSpeke20Audio:EncryptionContractConfiguration' :: EncryptionContractConfiguration -> PresetSpeke20Audio
presetSpeke20Audio} -> PresetSpeke20Audio
presetSpeke20Audio) (\s :: EncryptionContractConfiguration
s@EncryptionContractConfiguration' {} PresetSpeke20Audio
a -> EncryptionContractConfiguration
s {$sel:presetSpeke20Audio:EncryptionContractConfiguration' :: PresetSpeke20Audio
presetSpeke20Audio = PresetSpeke20Audio
a} :: EncryptionContractConfiguration)

-- | A collection of video encryption presets.
encryptionContractConfiguration_presetSpeke20Video :: Lens.Lens' EncryptionContractConfiguration PresetSpeke20Video
encryptionContractConfiguration_presetSpeke20Video :: (PresetSpeke20Video -> f PresetSpeke20Video)
-> EncryptionContractConfiguration
-> f EncryptionContractConfiguration
encryptionContractConfiguration_presetSpeke20Video = (EncryptionContractConfiguration -> PresetSpeke20Video)
-> (EncryptionContractConfiguration
    -> PresetSpeke20Video -> EncryptionContractConfiguration)
-> Lens
     EncryptionContractConfiguration
     EncryptionContractConfiguration
     PresetSpeke20Video
     PresetSpeke20Video
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionContractConfiguration' {PresetSpeke20Video
presetSpeke20Video :: PresetSpeke20Video
$sel:presetSpeke20Video:EncryptionContractConfiguration' :: EncryptionContractConfiguration -> PresetSpeke20Video
presetSpeke20Video} -> PresetSpeke20Video
presetSpeke20Video) (\s :: EncryptionContractConfiguration
s@EncryptionContractConfiguration' {} PresetSpeke20Video
a -> EncryptionContractConfiguration
s {$sel:presetSpeke20Video:EncryptionContractConfiguration' :: PresetSpeke20Video
presetSpeke20Video = PresetSpeke20Video
a} :: EncryptionContractConfiguration)

instance
  Core.FromJSON
    EncryptionContractConfiguration
  where
  parseJSON :: Value -> Parser EncryptionContractConfiguration
parseJSON =
    String
-> (Object -> Parser EncryptionContractConfiguration)
-> Value
-> Parser EncryptionContractConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EncryptionContractConfiguration"
      ( \Object
x ->
          PresetSpeke20Audio
-> PresetSpeke20Video -> EncryptionContractConfiguration
EncryptionContractConfiguration'
            (PresetSpeke20Audio
 -> PresetSpeke20Video -> EncryptionContractConfiguration)
-> Parser PresetSpeke20Audio
-> Parser (PresetSpeke20Video -> EncryptionContractConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser PresetSpeke20Audio
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"presetSpeke20Audio")
            Parser (PresetSpeke20Video -> EncryptionContractConfiguration)
-> Parser PresetSpeke20Video
-> Parser EncryptionContractConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser PresetSpeke20Video
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"presetSpeke20Video")
      )

instance
  Prelude.Hashable
    EncryptionContractConfiguration

instance
  Prelude.NFData
    EncryptionContractConfiguration

instance Core.ToJSON EncryptionContractConfiguration where
  toJSON :: EncryptionContractConfiguration -> Value
toJSON EncryptionContractConfiguration' {PresetSpeke20Audio
PresetSpeke20Video
presetSpeke20Video :: PresetSpeke20Video
presetSpeke20Audio :: PresetSpeke20Audio
$sel:presetSpeke20Video:EncryptionContractConfiguration' :: EncryptionContractConfiguration -> PresetSpeke20Video
$sel:presetSpeke20Audio:EncryptionContractConfiguration' :: EncryptionContractConfiguration -> PresetSpeke20Audio
..} =
    [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
"presetSpeke20Audio" Text -> PresetSpeke20Audio -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PresetSpeke20Audio
presetSpeke20Audio),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"presetSpeke20Video" Text -> PresetSpeke20Video -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PresetSpeke20Video
presetSpeke20Video)
          ]
      )