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

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

-- | A complex type that contains settings that determine how and when that
-- MediaTailor places prefetched ads into upcoming ad breaks.
--
-- /See:/ 'newPrefetchConsumption' smart constructor.
data PrefetchConsumption = PrefetchConsumption'
  { -- | The time when prefetched ads are considered for use in an ad break. If
    -- you don\'t specify StartTime, the prefetched ads are available after
    -- MediaTailor retrives them from the ad decision server.
    PrefetchConsumption -> Maybe POSIX
startTime :: Prelude.Maybe Core.POSIX,
    -- | If you only want MediaTailor to insert prefetched ads into avails (ad
    -- breaks) that match specific dynamic variables, such as scte.event_id,
    -- set the avail matching criteria.
    PrefetchConsumption -> Maybe [AvailMatchingCriteria]
availMatchingCriteria :: Prelude.Maybe [AvailMatchingCriteria],
    -- | The time when MediaTailor no longer considers the prefetched ads for use
    -- in an ad break. MediaTailor automatically deletes prefetch schedules no
    -- less than seven days after the end time. If you\'d like to manually
    -- delete the prefetch schedule, you can call DeletePrefetchSchedule.
    PrefetchConsumption -> POSIX
endTime :: Core.POSIX
  }
  deriving (PrefetchConsumption -> PrefetchConsumption -> Bool
(PrefetchConsumption -> PrefetchConsumption -> Bool)
-> (PrefetchConsumption -> PrefetchConsumption -> Bool)
-> Eq PrefetchConsumption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrefetchConsumption -> PrefetchConsumption -> Bool
$c/= :: PrefetchConsumption -> PrefetchConsumption -> Bool
== :: PrefetchConsumption -> PrefetchConsumption -> Bool
$c== :: PrefetchConsumption -> PrefetchConsumption -> Bool
Prelude.Eq, ReadPrec [PrefetchConsumption]
ReadPrec PrefetchConsumption
Int -> ReadS PrefetchConsumption
ReadS [PrefetchConsumption]
(Int -> ReadS PrefetchConsumption)
-> ReadS [PrefetchConsumption]
-> ReadPrec PrefetchConsumption
-> ReadPrec [PrefetchConsumption]
-> Read PrefetchConsumption
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PrefetchConsumption]
$creadListPrec :: ReadPrec [PrefetchConsumption]
readPrec :: ReadPrec PrefetchConsumption
$creadPrec :: ReadPrec PrefetchConsumption
readList :: ReadS [PrefetchConsumption]
$creadList :: ReadS [PrefetchConsumption]
readsPrec :: Int -> ReadS PrefetchConsumption
$creadsPrec :: Int -> ReadS PrefetchConsumption
Prelude.Read, Int -> PrefetchConsumption -> ShowS
[PrefetchConsumption] -> ShowS
PrefetchConsumption -> String
(Int -> PrefetchConsumption -> ShowS)
-> (PrefetchConsumption -> String)
-> ([PrefetchConsumption] -> ShowS)
-> Show PrefetchConsumption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrefetchConsumption] -> ShowS
$cshowList :: [PrefetchConsumption] -> ShowS
show :: PrefetchConsumption -> String
$cshow :: PrefetchConsumption -> String
showsPrec :: Int -> PrefetchConsumption -> ShowS
$cshowsPrec :: Int -> PrefetchConsumption -> ShowS
Prelude.Show, (forall x. PrefetchConsumption -> Rep PrefetchConsumption x)
-> (forall x. Rep PrefetchConsumption x -> PrefetchConsumption)
-> Generic PrefetchConsumption
forall x. Rep PrefetchConsumption x -> PrefetchConsumption
forall x. PrefetchConsumption -> Rep PrefetchConsumption x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PrefetchConsumption x -> PrefetchConsumption
$cfrom :: forall x. PrefetchConsumption -> Rep PrefetchConsumption x
Prelude.Generic)

-- |
-- Create a value of 'PrefetchConsumption' 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:
--
-- 'startTime', 'prefetchConsumption_startTime' - The time when prefetched ads are considered for use in an ad break. If
-- you don\'t specify StartTime, the prefetched ads are available after
-- MediaTailor retrives them from the ad decision server.
--
-- 'availMatchingCriteria', 'prefetchConsumption_availMatchingCriteria' - If you only want MediaTailor to insert prefetched ads into avails (ad
-- breaks) that match specific dynamic variables, such as scte.event_id,
-- set the avail matching criteria.
--
-- 'endTime', 'prefetchConsumption_endTime' - The time when MediaTailor no longer considers the prefetched ads for use
-- in an ad break. MediaTailor automatically deletes prefetch schedules no
-- less than seven days after the end time. If you\'d like to manually
-- delete the prefetch schedule, you can call DeletePrefetchSchedule.
newPrefetchConsumption ::
  -- | 'endTime'
  Prelude.UTCTime ->
  PrefetchConsumption
newPrefetchConsumption :: UTCTime -> PrefetchConsumption
newPrefetchConsumption UTCTime
pEndTime_ =
  PrefetchConsumption' :: Maybe POSIX
-> Maybe [AvailMatchingCriteria] -> POSIX -> PrefetchConsumption
PrefetchConsumption'
    { $sel:startTime:PrefetchConsumption' :: Maybe POSIX
startTime = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:availMatchingCriteria:PrefetchConsumption' :: Maybe [AvailMatchingCriteria]
availMatchingCriteria = Maybe [AvailMatchingCriteria]
forall a. Maybe a
Prelude.Nothing,
      $sel:endTime:PrefetchConsumption' :: POSIX
endTime = Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pEndTime_
    }

-- | The time when prefetched ads are considered for use in an ad break. If
-- you don\'t specify StartTime, the prefetched ads are available after
-- MediaTailor retrives them from the ad decision server.
prefetchConsumption_startTime :: Lens.Lens' PrefetchConsumption (Prelude.Maybe Prelude.UTCTime)
prefetchConsumption_startTime :: (Maybe UTCTime -> f (Maybe UTCTime))
-> PrefetchConsumption -> f PrefetchConsumption
prefetchConsumption_startTime = (PrefetchConsumption -> Maybe POSIX)
-> (PrefetchConsumption -> Maybe POSIX -> PrefetchConsumption)
-> Lens
     PrefetchConsumption PrefetchConsumption (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PrefetchConsumption' {Maybe POSIX
startTime :: Maybe POSIX
$sel:startTime:PrefetchConsumption' :: PrefetchConsumption -> Maybe POSIX
startTime} -> Maybe POSIX
startTime) (\s :: PrefetchConsumption
s@PrefetchConsumption' {} Maybe POSIX
a -> PrefetchConsumption
s {$sel:startTime:PrefetchConsumption' :: Maybe POSIX
startTime = Maybe POSIX
a} :: PrefetchConsumption) ((Maybe POSIX -> f (Maybe POSIX))
 -> PrefetchConsumption -> f PrefetchConsumption)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> PrefetchConsumption
-> f PrefetchConsumption
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | If you only want MediaTailor to insert prefetched ads into avails (ad
-- breaks) that match specific dynamic variables, such as scte.event_id,
-- set the avail matching criteria.
prefetchConsumption_availMatchingCriteria :: Lens.Lens' PrefetchConsumption (Prelude.Maybe [AvailMatchingCriteria])
prefetchConsumption_availMatchingCriteria :: (Maybe [AvailMatchingCriteria]
 -> f (Maybe [AvailMatchingCriteria]))
-> PrefetchConsumption -> f PrefetchConsumption
prefetchConsumption_availMatchingCriteria = (PrefetchConsumption -> Maybe [AvailMatchingCriteria])
-> (PrefetchConsumption
    -> Maybe [AvailMatchingCriteria] -> PrefetchConsumption)
-> Lens
     PrefetchConsumption
     PrefetchConsumption
     (Maybe [AvailMatchingCriteria])
     (Maybe [AvailMatchingCriteria])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PrefetchConsumption' {Maybe [AvailMatchingCriteria]
availMatchingCriteria :: Maybe [AvailMatchingCriteria]
$sel:availMatchingCriteria:PrefetchConsumption' :: PrefetchConsumption -> Maybe [AvailMatchingCriteria]
availMatchingCriteria} -> Maybe [AvailMatchingCriteria]
availMatchingCriteria) (\s :: PrefetchConsumption
s@PrefetchConsumption' {} Maybe [AvailMatchingCriteria]
a -> PrefetchConsumption
s {$sel:availMatchingCriteria:PrefetchConsumption' :: Maybe [AvailMatchingCriteria]
availMatchingCriteria = Maybe [AvailMatchingCriteria]
a} :: PrefetchConsumption) ((Maybe [AvailMatchingCriteria]
  -> f (Maybe [AvailMatchingCriteria]))
 -> PrefetchConsumption -> f PrefetchConsumption)
-> ((Maybe [AvailMatchingCriteria]
     -> f (Maybe [AvailMatchingCriteria]))
    -> Maybe [AvailMatchingCriteria]
    -> f (Maybe [AvailMatchingCriteria]))
-> (Maybe [AvailMatchingCriteria]
    -> f (Maybe [AvailMatchingCriteria]))
-> PrefetchConsumption
-> f PrefetchConsumption
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [AvailMatchingCriteria]
  [AvailMatchingCriteria]
  [AvailMatchingCriteria]
  [AvailMatchingCriteria]
-> Iso
     (Maybe [AvailMatchingCriteria])
     (Maybe [AvailMatchingCriteria])
     (Maybe [AvailMatchingCriteria])
     (Maybe [AvailMatchingCriteria])
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
  [AvailMatchingCriteria]
  [AvailMatchingCriteria]
  [AvailMatchingCriteria]
  [AvailMatchingCriteria]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The time when MediaTailor no longer considers the prefetched ads for use
-- in an ad break. MediaTailor automatically deletes prefetch schedules no
-- less than seven days after the end time. If you\'d like to manually
-- delete the prefetch schedule, you can call DeletePrefetchSchedule.
prefetchConsumption_endTime :: Lens.Lens' PrefetchConsumption Prelude.UTCTime
prefetchConsumption_endTime :: (UTCTime -> f UTCTime)
-> PrefetchConsumption -> f PrefetchConsumption
prefetchConsumption_endTime = (PrefetchConsumption -> POSIX)
-> (PrefetchConsumption -> POSIX -> PrefetchConsumption)
-> Lens PrefetchConsumption PrefetchConsumption POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PrefetchConsumption' {POSIX
endTime :: POSIX
$sel:endTime:PrefetchConsumption' :: PrefetchConsumption -> POSIX
endTime} -> POSIX
endTime) (\s :: PrefetchConsumption
s@PrefetchConsumption' {} POSIX
a -> PrefetchConsumption
s {$sel:endTime:PrefetchConsumption' :: POSIX
endTime = POSIX
a} :: PrefetchConsumption) ((POSIX -> f POSIX)
 -> PrefetchConsumption -> f PrefetchConsumption)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> PrefetchConsumption
-> f PrefetchConsumption
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

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

instance Prelude.Hashable PrefetchConsumption

instance Prelude.NFData PrefetchConsumption

instance Core.ToJSON PrefetchConsumption where
  toJSON :: PrefetchConsumption -> Value
toJSON PrefetchConsumption' {Maybe [AvailMatchingCriteria]
Maybe POSIX
POSIX
endTime :: POSIX
availMatchingCriteria :: Maybe [AvailMatchingCriteria]
startTime :: Maybe POSIX
$sel:endTime:PrefetchConsumption' :: PrefetchConsumption -> POSIX
$sel:availMatchingCriteria:PrefetchConsumption' :: PrefetchConsumption -> Maybe [AvailMatchingCriteria]
$sel:startTime:PrefetchConsumption' :: PrefetchConsumption -> Maybe POSIX
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"StartTime" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (POSIX -> Pair) -> Maybe POSIX -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe POSIX
startTime,
            (Text
"AvailMatchingCriteria" Text -> [AvailMatchingCriteria] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([AvailMatchingCriteria] -> Pair)
-> Maybe [AvailMatchingCriteria] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [AvailMatchingCriteria]
availMatchingCriteria,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"EndTime" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= POSIX
endTime)
          ]
      )