{-# 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.LicenseManager.Types.ReportFrequency
-- 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.LicenseManager.Types.ReportFrequency where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.LicenseManager.Types.ReportFrequencyType
import qualified Amazonka.Prelude as Prelude

-- | Details about how frequently reports are generated.
--
-- /See:/ 'newReportFrequency' smart constructor.
data ReportFrequency = ReportFrequency'
  { -- | Time period between each report. The period can be daily, weekly, or
    -- monthly.
    ReportFrequency -> Maybe ReportFrequencyType
period :: Prelude.Maybe ReportFrequencyType,
    -- | Number of times within the frequency period that a report is generated.
    -- The only supported value is @1@.
    ReportFrequency -> Maybe Int
value :: Prelude.Maybe Prelude.Int
  }
  deriving (ReportFrequency -> ReportFrequency -> Bool
(ReportFrequency -> ReportFrequency -> Bool)
-> (ReportFrequency -> ReportFrequency -> Bool)
-> Eq ReportFrequency
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReportFrequency -> ReportFrequency -> Bool
$c/= :: ReportFrequency -> ReportFrequency -> Bool
== :: ReportFrequency -> ReportFrequency -> Bool
$c== :: ReportFrequency -> ReportFrequency -> Bool
Prelude.Eq, ReadPrec [ReportFrequency]
ReadPrec ReportFrequency
Int -> ReadS ReportFrequency
ReadS [ReportFrequency]
(Int -> ReadS ReportFrequency)
-> ReadS [ReportFrequency]
-> ReadPrec ReportFrequency
-> ReadPrec [ReportFrequency]
-> Read ReportFrequency
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReportFrequency]
$creadListPrec :: ReadPrec [ReportFrequency]
readPrec :: ReadPrec ReportFrequency
$creadPrec :: ReadPrec ReportFrequency
readList :: ReadS [ReportFrequency]
$creadList :: ReadS [ReportFrequency]
readsPrec :: Int -> ReadS ReportFrequency
$creadsPrec :: Int -> ReadS ReportFrequency
Prelude.Read, Int -> ReportFrequency -> ShowS
[ReportFrequency] -> ShowS
ReportFrequency -> String
(Int -> ReportFrequency -> ShowS)
-> (ReportFrequency -> String)
-> ([ReportFrequency] -> ShowS)
-> Show ReportFrequency
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReportFrequency] -> ShowS
$cshowList :: [ReportFrequency] -> ShowS
show :: ReportFrequency -> String
$cshow :: ReportFrequency -> String
showsPrec :: Int -> ReportFrequency -> ShowS
$cshowsPrec :: Int -> ReportFrequency -> ShowS
Prelude.Show, (forall x. ReportFrequency -> Rep ReportFrequency x)
-> (forall x. Rep ReportFrequency x -> ReportFrequency)
-> Generic ReportFrequency
forall x. Rep ReportFrequency x -> ReportFrequency
forall x. ReportFrequency -> Rep ReportFrequency x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReportFrequency x -> ReportFrequency
$cfrom :: forall x. ReportFrequency -> Rep ReportFrequency x
Prelude.Generic)

-- |
-- Create a value of 'ReportFrequency' 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:
--
-- 'period', 'reportFrequency_period' - Time period between each report. The period can be daily, weekly, or
-- monthly.
--
-- 'value', 'reportFrequency_value' - Number of times within the frequency period that a report is generated.
-- The only supported value is @1@.
newReportFrequency ::
  ReportFrequency
newReportFrequency :: ReportFrequency
newReportFrequency =
  ReportFrequency' :: Maybe ReportFrequencyType -> Maybe Int -> ReportFrequency
ReportFrequency'
    { $sel:period:ReportFrequency' :: Maybe ReportFrequencyType
period = Maybe ReportFrequencyType
forall a. Maybe a
Prelude.Nothing,
      $sel:value:ReportFrequency' :: Maybe Int
value = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | Time period between each report. The period can be daily, weekly, or
-- monthly.
reportFrequency_period :: Lens.Lens' ReportFrequency (Prelude.Maybe ReportFrequencyType)
reportFrequency_period :: (Maybe ReportFrequencyType -> f (Maybe ReportFrequencyType))
-> ReportFrequency -> f ReportFrequency
reportFrequency_period = (ReportFrequency -> Maybe ReportFrequencyType)
-> (ReportFrequency
    -> Maybe ReportFrequencyType -> ReportFrequency)
-> Lens
     ReportFrequency
     ReportFrequency
     (Maybe ReportFrequencyType)
     (Maybe ReportFrequencyType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReportFrequency' {Maybe ReportFrequencyType
period :: Maybe ReportFrequencyType
$sel:period:ReportFrequency' :: ReportFrequency -> Maybe ReportFrequencyType
period} -> Maybe ReportFrequencyType
period) (\s :: ReportFrequency
s@ReportFrequency' {} Maybe ReportFrequencyType
a -> ReportFrequency
s {$sel:period:ReportFrequency' :: Maybe ReportFrequencyType
period = Maybe ReportFrequencyType
a} :: ReportFrequency)

-- | Number of times within the frequency period that a report is generated.
-- The only supported value is @1@.
reportFrequency_value :: Lens.Lens' ReportFrequency (Prelude.Maybe Prelude.Int)
reportFrequency_value :: (Maybe Int -> f (Maybe Int))
-> ReportFrequency -> f ReportFrequency
reportFrequency_value = (ReportFrequency -> Maybe Int)
-> (ReportFrequency -> Maybe Int -> ReportFrequency)
-> Lens ReportFrequency ReportFrequency (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReportFrequency' {Maybe Int
value :: Maybe Int
$sel:value:ReportFrequency' :: ReportFrequency -> Maybe Int
value} -> Maybe Int
value) (\s :: ReportFrequency
s@ReportFrequency' {} Maybe Int
a -> ReportFrequency
s {$sel:value:ReportFrequency' :: Maybe Int
value = Maybe Int
a} :: ReportFrequency)

instance Core.FromJSON ReportFrequency where
  parseJSON :: Value -> Parser ReportFrequency
parseJSON =
    String
-> (Object -> Parser ReportFrequency)
-> Value
-> Parser ReportFrequency
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ReportFrequency"
      ( \Object
x ->
          Maybe ReportFrequencyType -> Maybe Int -> ReportFrequency
ReportFrequency'
            (Maybe ReportFrequencyType -> Maybe Int -> ReportFrequency)
-> Parser (Maybe ReportFrequencyType)
-> Parser (Maybe Int -> ReportFrequency)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ReportFrequencyType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"period")
            Parser (Maybe Int -> ReportFrequency)
-> Parser (Maybe Int) -> Parser ReportFrequency
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"value")
      )

instance Prelude.Hashable ReportFrequency

instance Prelude.NFData ReportFrequency

instance Core.ToJSON ReportFrequency where
  toJSON :: ReportFrequency -> Value
toJSON ReportFrequency' {Maybe Int
Maybe ReportFrequencyType
value :: Maybe Int
period :: Maybe ReportFrequencyType
$sel:value:ReportFrequency' :: ReportFrequency -> Maybe Int
$sel:period:ReportFrequency' :: ReportFrequency -> Maybe ReportFrequencyType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"period" Text -> ReportFrequencyType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ReportFrequencyType -> Pair)
-> Maybe ReportFrequencyType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ReportFrequencyType
period,
            (Text
"value" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
value
          ]
      )