{-# 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.DeviceFarm.Types.RecurringCharge
-- 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.DeviceFarm.Types.RecurringCharge where

import qualified Amazonka.Core as Core
import Amazonka.DeviceFarm.Types.MonetaryAmount
import Amazonka.DeviceFarm.Types.RecurringChargeFrequency
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies whether charges for devices are recurring.
--
-- /See:/ 'newRecurringCharge' smart constructor.
data RecurringCharge = RecurringCharge'
  { -- | The frequency in which charges recur.
    RecurringCharge -> Maybe RecurringChargeFrequency
frequency :: Prelude.Maybe RecurringChargeFrequency,
    -- | The cost of the recurring charge.
    RecurringCharge -> Maybe MonetaryAmount
cost :: Prelude.Maybe MonetaryAmount
  }
  deriving (RecurringCharge -> RecurringCharge -> Bool
(RecurringCharge -> RecurringCharge -> Bool)
-> (RecurringCharge -> RecurringCharge -> Bool)
-> Eq RecurringCharge
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecurringCharge -> RecurringCharge -> Bool
$c/= :: RecurringCharge -> RecurringCharge -> Bool
== :: RecurringCharge -> RecurringCharge -> Bool
$c== :: RecurringCharge -> RecurringCharge -> Bool
Prelude.Eq, ReadPrec [RecurringCharge]
ReadPrec RecurringCharge
Int -> ReadS RecurringCharge
ReadS [RecurringCharge]
(Int -> ReadS RecurringCharge)
-> ReadS [RecurringCharge]
-> ReadPrec RecurringCharge
-> ReadPrec [RecurringCharge]
-> Read RecurringCharge
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RecurringCharge]
$creadListPrec :: ReadPrec [RecurringCharge]
readPrec :: ReadPrec RecurringCharge
$creadPrec :: ReadPrec RecurringCharge
readList :: ReadS [RecurringCharge]
$creadList :: ReadS [RecurringCharge]
readsPrec :: Int -> ReadS RecurringCharge
$creadsPrec :: Int -> ReadS RecurringCharge
Prelude.Read, Int -> RecurringCharge -> ShowS
[RecurringCharge] -> ShowS
RecurringCharge -> String
(Int -> RecurringCharge -> ShowS)
-> (RecurringCharge -> String)
-> ([RecurringCharge] -> ShowS)
-> Show RecurringCharge
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecurringCharge] -> ShowS
$cshowList :: [RecurringCharge] -> ShowS
show :: RecurringCharge -> String
$cshow :: RecurringCharge -> String
showsPrec :: Int -> RecurringCharge -> ShowS
$cshowsPrec :: Int -> RecurringCharge -> ShowS
Prelude.Show, (forall x. RecurringCharge -> Rep RecurringCharge x)
-> (forall x. Rep RecurringCharge x -> RecurringCharge)
-> Generic RecurringCharge
forall x. Rep RecurringCharge x -> RecurringCharge
forall x. RecurringCharge -> Rep RecurringCharge x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RecurringCharge x -> RecurringCharge
$cfrom :: forall x. RecurringCharge -> Rep RecurringCharge x
Prelude.Generic)

-- |
-- Create a value of 'RecurringCharge' 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:
--
-- 'frequency', 'recurringCharge_frequency' - The frequency in which charges recur.
--
-- 'cost', 'recurringCharge_cost' - The cost of the recurring charge.
newRecurringCharge ::
  RecurringCharge
newRecurringCharge :: RecurringCharge
newRecurringCharge =
  RecurringCharge' :: Maybe RecurringChargeFrequency
-> Maybe MonetaryAmount -> RecurringCharge
RecurringCharge'
    { $sel:frequency:RecurringCharge' :: Maybe RecurringChargeFrequency
frequency = Maybe RecurringChargeFrequency
forall a. Maybe a
Prelude.Nothing,
      $sel:cost:RecurringCharge' :: Maybe MonetaryAmount
cost = Maybe MonetaryAmount
forall a. Maybe a
Prelude.Nothing
    }

-- | The frequency in which charges recur.
recurringCharge_frequency :: Lens.Lens' RecurringCharge (Prelude.Maybe RecurringChargeFrequency)
recurringCharge_frequency :: (Maybe RecurringChargeFrequency
 -> f (Maybe RecurringChargeFrequency))
-> RecurringCharge -> f RecurringCharge
recurringCharge_frequency = (RecurringCharge -> Maybe RecurringChargeFrequency)
-> (RecurringCharge
    -> Maybe RecurringChargeFrequency -> RecurringCharge)
-> Lens
     RecurringCharge
     RecurringCharge
     (Maybe RecurringChargeFrequency)
     (Maybe RecurringChargeFrequency)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecurringCharge' {Maybe RecurringChargeFrequency
frequency :: Maybe RecurringChargeFrequency
$sel:frequency:RecurringCharge' :: RecurringCharge -> Maybe RecurringChargeFrequency
frequency} -> Maybe RecurringChargeFrequency
frequency) (\s :: RecurringCharge
s@RecurringCharge' {} Maybe RecurringChargeFrequency
a -> RecurringCharge
s {$sel:frequency:RecurringCharge' :: Maybe RecurringChargeFrequency
frequency = Maybe RecurringChargeFrequency
a} :: RecurringCharge)

-- | The cost of the recurring charge.
recurringCharge_cost :: Lens.Lens' RecurringCharge (Prelude.Maybe MonetaryAmount)
recurringCharge_cost :: (Maybe MonetaryAmount -> f (Maybe MonetaryAmount))
-> RecurringCharge -> f RecurringCharge
recurringCharge_cost = (RecurringCharge -> Maybe MonetaryAmount)
-> (RecurringCharge -> Maybe MonetaryAmount -> RecurringCharge)
-> Lens
     RecurringCharge
     RecurringCharge
     (Maybe MonetaryAmount)
     (Maybe MonetaryAmount)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecurringCharge' {Maybe MonetaryAmount
cost :: Maybe MonetaryAmount
$sel:cost:RecurringCharge' :: RecurringCharge -> Maybe MonetaryAmount
cost} -> Maybe MonetaryAmount
cost) (\s :: RecurringCharge
s@RecurringCharge' {} Maybe MonetaryAmount
a -> RecurringCharge
s {$sel:cost:RecurringCharge' :: Maybe MonetaryAmount
cost = Maybe MonetaryAmount
a} :: RecurringCharge)

instance Core.FromJSON RecurringCharge where
  parseJSON :: Value -> Parser RecurringCharge
parseJSON =
    String
-> (Object -> Parser RecurringCharge)
-> Value
-> Parser RecurringCharge
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RecurringCharge"
      ( \Object
x ->
          Maybe RecurringChargeFrequency
-> Maybe MonetaryAmount -> RecurringCharge
RecurringCharge'
            (Maybe RecurringChargeFrequency
 -> Maybe MonetaryAmount -> RecurringCharge)
-> Parser (Maybe RecurringChargeFrequency)
-> Parser (Maybe MonetaryAmount -> RecurringCharge)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe RecurringChargeFrequency)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"frequency")
            Parser (Maybe MonetaryAmount -> RecurringCharge)
-> Parser (Maybe MonetaryAmount) -> Parser RecurringCharge
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe MonetaryAmount)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"cost")
      )

instance Prelude.Hashable RecurringCharge

instance Prelude.NFData RecurringCharge