{-# 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.MediaTailor.Types.AvailMatchingCriteria
-- 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.MediaTailor.Types.AvailMatchingCriteria where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MediaTailor.Types.Operator
import qualified Amazonka.Prelude as Prelude

-- | MediaTailor only places (consumes) prefetched ads if the ad break meets
-- the criteria defined by the dynamic variables. This gives you granular
-- control over which ad break to place the prefetched ads into.
--
-- As an example, let\'s say that you set DynamicVariable to scte.event_id
-- and Operator to EQUALS, and your playback configuration has an ADS URL
-- of
-- https:\/\/my.ads.server.com\/path?&podId=[scte.avail_num]&event=[scte.event_id]&duration=[session.avail_duration_secs].
-- And the prefetch request to the ADS contains these values
-- https:\/\/my.ads.server.com\/path?&podId=3&event=my-awesome-event&duration=30.
-- MediaTailor will only insert the prefetched ads into the ad break if has
-- a SCTE marker with an event id of my-awesome-event, since it must match
-- the event id that MediaTailor uses to query the ADS.
--
-- You can specify up to five AvailMatchingCriteria. If you specify
-- multiple AvailMatchingCriteria, MediaTailor combines them to match using
-- a logical AND. You can model logical OR combinations by creating
-- multiple prefetch schedules.
--
-- /See:/ 'newAvailMatchingCriteria' smart constructor.
data AvailMatchingCriteria = AvailMatchingCriteria'
  { -- | For the DynamicVariable specified in AvailMatchingCriteria, the Operator
    -- that is used for the comparison.
    AvailMatchingCriteria -> Operator
operator :: Operator,
    -- | The dynamic variable(s) that MediaTailor should use as avail matching
    -- criteria. MediaTailor only places the prefetched ads into the avail if
    -- the avail matches the criteria defined by the dynamic variable. For
    -- information about dynamic variables, see
    -- <https://docs.aws.amazon.com/mediatailor/latest/ug/variables.html Using dynamic ad variables>
    -- in the /MediaTailor User Guide/.
    --
    -- You can include up to 100 dynamic variables.
    AvailMatchingCriteria -> Text
dynamicVariable :: Prelude.Text
  }
  deriving (AvailMatchingCriteria -> AvailMatchingCriteria -> Bool
(AvailMatchingCriteria -> AvailMatchingCriteria -> Bool)
-> (AvailMatchingCriteria -> AvailMatchingCriteria -> Bool)
-> Eq AvailMatchingCriteria
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AvailMatchingCriteria -> AvailMatchingCriteria -> Bool
$c/= :: AvailMatchingCriteria -> AvailMatchingCriteria -> Bool
== :: AvailMatchingCriteria -> AvailMatchingCriteria -> Bool
$c== :: AvailMatchingCriteria -> AvailMatchingCriteria -> Bool
Prelude.Eq, ReadPrec [AvailMatchingCriteria]
ReadPrec AvailMatchingCriteria
Int -> ReadS AvailMatchingCriteria
ReadS [AvailMatchingCriteria]
(Int -> ReadS AvailMatchingCriteria)
-> ReadS [AvailMatchingCriteria]
-> ReadPrec AvailMatchingCriteria
-> ReadPrec [AvailMatchingCriteria]
-> Read AvailMatchingCriteria
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AvailMatchingCriteria]
$creadListPrec :: ReadPrec [AvailMatchingCriteria]
readPrec :: ReadPrec AvailMatchingCriteria
$creadPrec :: ReadPrec AvailMatchingCriteria
readList :: ReadS [AvailMatchingCriteria]
$creadList :: ReadS [AvailMatchingCriteria]
readsPrec :: Int -> ReadS AvailMatchingCriteria
$creadsPrec :: Int -> ReadS AvailMatchingCriteria
Prelude.Read, Int -> AvailMatchingCriteria -> ShowS
[AvailMatchingCriteria] -> ShowS
AvailMatchingCriteria -> String
(Int -> AvailMatchingCriteria -> ShowS)
-> (AvailMatchingCriteria -> String)
-> ([AvailMatchingCriteria] -> ShowS)
-> Show AvailMatchingCriteria
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AvailMatchingCriteria] -> ShowS
$cshowList :: [AvailMatchingCriteria] -> ShowS
show :: AvailMatchingCriteria -> String
$cshow :: AvailMatchingCriteria -> String
showsPrec :: Int -> AvailMatchingCriteria -> ShowS
$cshowsPrec :: Int -> AvailMatchingCriteria -> ShowS
Prelude.Show, (forall x. AvailMatchingCriteria -> Rep AvailMatchingCriteria x)
-> (forall x. Rep AvailMatchingCriteria x -> AvailMatchingCriteria)
-> Generic AvailMatchingCriteria
forall x. Rep AvailMatchingCriteria x -> AvailMatchingCriteria
forall x. AvailMatchingCriteria -> Rep AvailMatchingCriteria x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AvailMatchingCriteria x -> AvailMatchingCriteria
$cfrom :: forall x. AvailMatchingCriteria -> Rep AvailMatchingCriteria x
Prelude.Generic)

-- |
-- Create a value of 'AvailMatchingCriteria' 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:
--
-- 'operator', 'availMatchingCriteria_operator' - For the DynamicVariable specified in AvailMatchingCriteria, the Operator
-- that is used for the comparison.
--
-- 'dynamicVariable', 'availMatchingCriteria_dynamicVariable' - The dynamic variable(s) that MediaTailor should use as avail matching
-- criteria. MediaTailor only places the prefetched ads into the avail if
-- the avail matches the criteria defined by the dynamic variable. For
-- information about dynamic variables, see
-- <https://docs.aws.amazon.com/mediatailor/latest/ug/variables.html Using dynamic ad variables>
-- in the /MediaTailor User Guide/.
--
-- You can include up to 100 dynamic variables.
newAvailMatchingCriteria ::
  -- | 'operator'
  Operator ->
  -- | 'dynamicVariable'
  Prelude.Text ->
  AvailMatchingCriteria
newAvailMatchingCriteria :: Operator -> Text -> AvailMatchingCriteria
newAvailMatchingCriteria Operator
pOperator_ Text
pDynamicVariable_ =
  AvailMatchingCriteria' :: Operator -> Text -> AvailMatchingCriteria
AvailMatchingCriteria'
    { $sel:operator:AvailMatchingCriteria' :: Operator
operator = Operator
pOperator_,
      $sel:dynamicVariable:AvailMatchingCriteria' :: Text
dynamicVariable = Text
pDynamicVariable_
    }

-- | For the DynamicVariable specified in AvailMatchingCriteria, the Operator
-- that is used for the comparison.
availMatchingCriteria_operator :: Lens.Lens' AvailMatchingCriteria Operator
availMatchingCriteria_operator :: (Operator -> f Operator)
-> AvailMatchingCriteria -> f AvailMatchingCriteria
availMatchingCriteria_operator = (AvailMatchingCriteria -> Operator)
-> (AvailMatchingCriteria -> Operator -> AvailMatchingCriteria)
-> Lens
     AvailMatchingCriteria AvailMatchingCriteria Operator Operator
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AvailMatchingCriteria' {Operator
operator :: Operator
$sel:operator:AvailMatchingCriteria' :: AvailMatchingCriteria -> Operator
operator} -> Operator
operator) (\s :: AvailMatchingCriteria
s@AvailMatchingCriteria' {} Operator
a -> AvailMatchingCriteria
s {$sel:operator:AvailMatchingCriteria' :: Operator
operator = Operator
a} :: AvailMatchingCriteria)

-- | The dynamic variable(s) that MediaTailor should use as avail matching
-- criteria. MediaTailor only places the prefetched ads into the avail if
-- the avail matches the criteria defined by the dynamic variable. For
-- information about dynamic variables, see
-- <https://docs.aws.amazon.com/mediatailor/latest/ug/variables.html Using dynamic ad variables>
-- in the /MediaTailor User Guide/.
--
-- You can include up to 100 dynamic variables.
availMatchingCriteria_dynamicVariable :: Lens.Lens' AvailMatchingCriteria Prelude.Text
availMatchingCriteria_dynamicVariable :: (Text -> f Text)
-> AvailMatchingCriteria -> f AvailMatchingCriteria
availMatchingCriteria_dynamicVariable = (AvailMatchingCriteria -> Text)
-> (AvailMatchingCriteria -> Text -> AvailMatchingCriteria)
-> Lens AvailMatchingCriteria AvailMatchingCriteria Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AvailMatchingCriteria' {Text
dynamicVariable :: Text
$sel:dynamicVariable:AvailMatchingCriteria' :: AvailMatchingCriteria -> Text
dynamicVariable} -> Text
dynamicVariable) (\s :: AvailMatchingCriteria
s@AvailMatchingCriteria' {} Text
a -> AvailMatchingCriteria
s {$sel:dynamicVariable:AvailMatchingCriteria' :: Text
dynamicVariable = Text
a} :: AvailMatchingCriteria)

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

instance Prelude.Hashable AvailMatchingCriteria

instance Prelude.NFData AvailMatchingCriteria

instance Core.ToJSON AvailMatchingCriteria where
  toJSON :: AvailMatchingCriteria -> Value
toJSON AvailMatchingCriteria' {Text
Operator
dynamicVariable :: Text
operator :: Operator
$sel:dynamicVariable:AvailMatchingCriteria' :: AvailMatchingCriteria -> Text
$sel:operator:AvailMatchingCriteria' :: AvailMatchingCriteria -> Operator
..} =
    [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
"Operator" Text -> Operator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Operator
operator),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"DynamicVariable" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
dynamicVariable)
          ]
      )