{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.MediaTailor.Types.PrefetchConsumption where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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'
  { -- | 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 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 Data.POSIX,
    -- | 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 :: Data.POSIX
  }
  deriving (PrefetchConsumption -> PrefetchConsumption -> Bool
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]
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
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. 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:
--
-- '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.
--
-- '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.
--
-- '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'
    { $sel:availMatchingCriteria:PrefetchConsumption' :: Maybe [AvailMatchingCriteria]
availMatchingCriteria =
        forall a. Maybe a
Prelude.Nothing,
      $sel:startTime:PrefetchConsumption' :: Maybe POSIX
startTime = forall a. Maybe a
Prelude.Nothing,
      $sel:endTime:PrefetchConsumption' :: POSIX
endTime = forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pEndTime_
    }

-- | 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 :: Lens' PrefetchConsumption (Maybe [AvailMatchingCriteria])
prefetchConsumption_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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | 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 :: Lens' PrefetchConsumption (Maybe UTCTime)
prefetchConsumption_startTime = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | 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 :: Lens' PrefetchConsumption UTCTime
prefetchConsumption_endTime = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

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

instance Prelude.Hashable PrefetchConsumption where
  hashWithSalt :: Int -> PrefetchConsumption -> Int
hashWithSalt Int
_salt PrefetchConsumption' {Maybe [AvailMatchingCriteria]
Maybe POSIX
POSIX
endTime :: POSIX
startTime :: Maybe POSIX
availMatchingCriteria :: Maybe [AvailMatchingCriteria]
$sel:endTime:PrefetchConsumption' :: PrefetchConsumption -> POSIX
$sel:startTime:PrefetchConsumption' :: PrefetchConsumption -> Maybe POSIX
$sel:availMatchingCriteria:PrefetchConsumption' :: PrefetchConsumption -> Maybe [AvailMatchingCriteria]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [AvailMatchingCriteria]
availMatchingCriteria
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
startTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` POSIX
endTime

instance Prelude.NFData PrefetchConsumption where
  rnf :: PrefetchConsumption -> ()
rnf PrefetchConsumption' {Maybe [AvailMatchingCriteria]
Maybe POSIX
POSIX
endTime :: POSIX
startTime :: Maybe POSIX
availMatchingCriteria :: Maybe [AvailMatchingCriteria]
$sel:endTime:PrefetchConsumption' :: PrefetchConsumption -> POSIX
$sel:startTime:PrefetchConsumption' :: PrefetchConsumption -> Maybe POSIX
$sel:availMatchingCriteria:PrefetchConsumption' :: PrefetchConsumption -> Maybe [AvailMatchingCriteria]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [AvailMatchingCriteria]
availMatchingCriteria
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
startTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf POSIX
endTime

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