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

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

-- | Describes a resource entitled for use with a license.
--
-- /See:/ 'newEntitlement' smart constructor.
data Entitlement = Entitlement'
  { -- | Maximum entitlement count. Use if the unit is not None.
    Entitlement -> Maybe Integer
maxCount :: Prelude.Maybe Prelude.Integer,
    -- | Entitlement resource. Use only if the unit is None.
    Entitlement -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | Indicates whether overages are allowed.
    Entitlement -> Maybe Bool
overage :: Prelude.Maybe Prelude.Bool,
    -- | Indicates whether check-ins are allowed.
    Entitlement -> Maybe Bool
allowCheckIn :: Prelude.Maybe Prelude.Bool,
    -- | Entitlement name.
    Entitlement -> Text
name :: Prelude.Text,
    -- | Entitlement unit.
    Entitlement -> EntitlementUnit
unit :: EntitlementUnit
  }
  deriving (Entitlement -> Entitlement -> Bool
(Entitlement -> Entitlement -> Bool)
-> (Entitlement -> Entitlement -> Bool) -> Eq Entitlement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Entitlement -> Entitlement -> Bool
$c/= :: Entitlement -> Entitlement -> Bool
== :: Entitlement -> Entitlement -> Bool
$c== :: Entitlement -> Entitlement -> Bool
Prelude.Eq, ReadPrec [Entitlement]
ReadPrec Entitlement
Int -> ReadS Entitlement
ReadS [Entitlement]
(Int -> ReadS Entitlement)
-> ReadS [Entitlement]
-> ReadPrec Entitlement
-> ReadPrec [Entitlement]
-> Read Entitlement
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Entitlement]
$creadListPrec :: ReadPrec [Entitlement]
readPrec :: ReadPrec Entitlement
$creadPrec :: ReadPrec Entitlement
readList :: ReadS [Entitlement]
$creadList :: ReadS [Entitlement]
readsPrec :: Int -> ReadS Entitlement
$creadsPrec :: Int -> ReadS Entitlement
Prelude.Read, Int -> Entitlement -> ShowS
[Entitlement] -> ShowS
Entitlement -> String
(Int -> Entitlement -> ShowS)
-> (Entitlement -> String)
-> ([Entitlement] -> ShowS)
-> Show Entitlement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Entitlement] -> ShowS
$cshowList :: [Entitlement] -> ShowS
show :: Entitlement -> String
$cshow :: Entitlement -> String
showsPrec :: Int -> Entitlement -> ShowS
$cshowsPrec :: Int -> Entitlement -> ShowS
Prelude.Show, (forall x. Entitlement -> Rep Entitlement x)
-> (forall x. Rep Entitlement x -> Entitlement)
-> Generic Entitlement
forall x. Rep Entitlement x -> Entitlement
forall x. Entitlement -> Rep Entitlement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Entitlement x -> Entitlement
$cfrom :: forall x. Entitlement -> Rep Entitlement x
Prelude.Generic)

-- |
-- Create a value of 'Entitlement' 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:
--
-- 'maxCount', 'entitlement_maxCount' - Maximum entitlement count. Use if the unit is not None.
--
-- 'value', 'entitlement_value' - Entitlement resource. Use only if the unit is None.
--
-- 'overage', 'entitlement_overage' - Indicates whether overages are allowed.
--
-- 'allowCheckIn', 'entitlement_allowCheckIn' - Indicates whether check-ins are allowed.
--
-- 'name', 'entitlement_name' - Entitlement name.
--
-- 'unit', 'entitlement_unit' - Entitlement unit.
newEntitlement ::
  -- | 'name'
  Prelude.Text ->
  -- | 'unit'
  EntitlementUnit ->
  Entitlement
newEntitlement :: Text -> EntitlementUnit -> Entitlement
newEntitlement Text
pName_ EntitlementUnit
pUnit_ =
  Entitlement' :: Maybe Integer
-> Maybe Text
-> Maybe Bool
-> Maybe Bool
-> Text
-> EntitlementUnit
-> Entitlement
Entitlement'
    { $sel:maxCount:Entitlement' :: Maybe Integer
maxCount = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:value:Entitlement' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:overage:Entitlement' :: Maybe Bool
overage = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:allowCheckIn:Entitlement' :: Maybe Bool
allowCheckIn = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Entitlement' :: Text
name = Text
pName_,
      $sel:unit:Entitlement' :: EntitlementUnit
unit = EntitlementUnit
pUnit_
    }

-- | Maximum entitlement count. Use if the unit is not None.
entitlement_maxCount :: Lens.Lens' Entitlement (Prelude.Maybe Prelude.Integer)
entitlement_maxCount :: (Maybe Integer -> f (Maybe Integer))
-> Entitlement -> f Entitlement
entitlement_maxCount = (Entitlement -> Maybe Integer)
-> (Entitlement -> Maybe Integer -> Entitlement)
-> Lens Entitlement Entitlement (Maybe Integer) (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entitlement' {Maybe Integer
maxCount :: Maybe Integer
$sel:maxCount:Entitlement' :: Entitlement -> Maybe Integer
maxCount} -> Maybe Integer
maxCount) (\s :: Entitlement
s@Entitlement' {} Maybe Integer
a -> Entitlement
s {$sel:maxCount:Entitlement' :: Maybe Integer
maxCount = Maybe Integer
a} :: Entitlement)

-- | Entitlement resource. Use only if the unit is None.
entitlement_value :: Lens.Lens' Entitlement (Prelude.Maybe Prelude.Text)
entitlement_value :: (Maybe Text -> f (Maybe Text)) -> Entitlement -> f Entitlement
entitlement_value = (Entitlement -> Maybe Text)
-> (Entitlement -> Maybe Text -> Entitlement)
-> Lens Entitlement Entitlement (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entitlement' {Maybe Text
value :: Maybe Text
$sel:value:Entitlement' :: Entitlement -> Maybe Text
value} -> Maybe Text
value) (\s :: Entitlement
s@Entitlement' {} Maybe Text
a -> Entitlement
s {$sel:value:Entitlement' :: Maybe Text
value = Maybe Text
a} :: Entitlement)

-- | Indicates whether overages are allowed.
entitlement_overage :: Lens.Lens' Entitlement (Prelude.Maybe Prelude.Bool)
entitlement_overage :: (Maybe Bool -> f (Maybe Bool)) -> Entitlement -> f Entitlement
entitlement_overage = (Entitlement -> Maybe Bool)
-> (Entitlement -> Maybe Bool -> Entitlement)
-> Lens Entitlement Entitlement (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entitlement' {Maybe Bool
overage :: Maybe Bool
$sel:overage:Entitlement' :: Entitlement -> Maybe Bool
overage} -> Maybe Bool
overage) (\s :: Entitlement
s@Entitlement' {} Maybe Bool
a -> Entitlement
s {$sel:overage:Entitlement' :: Maybe Bool
overage = Maybe Bool
a} :: Entitlement)

-- | Indicates whether check-ins are allowed.
entitlement_allowCheckIn :: Lens.Lens' Entitlement (Prelude.Maybe Prelude.Bool)
entitlement_allowCheckIn :: (Maybe Bool -> f (Maybe Bool)) -> Entitlement -> f Entitlement
entitlement_allowCheckIn = (Entitlement -> Maybe Bool)
-> (Entitlement -> Maybe Bool -> Entitlement)
-> Lens Entitlement Entitlement (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entitlement' {Maybe Bool
allowCheckIn :: Maybe Bool
$sel:allowCheckIn:Entitlement' :: Entitlement -> Maybe Bool
allowCheckIn} -> Maybe Bool
allowCheckIn) (\s :: Entitlement
s@Entitlement' {} Maybe Bool
a -> Entitlement
s {$sel:allowCheckIn:Entitlement' :: Maybe Bool
allowCheckIn = Maybe Bool
a} :: Entitlement)

-- | Entitlement name.
entitlement_name :: Lens.Lens' Entitlement Prelude.Text
entitlement_name :: (Text -> f Text) -> Entitlement -> f Entitlement
entitlement_name = (Entitlement -> Text)
-> (Entitlement -> Text -> Entitlement)
-> Lens Entitlement Entitlement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entitlement' {Text
name :: Text
$sel:name:Entitlement' :: Entitlement -> Text
name} -> Text
name) (\s :: Entitlement
s@Entitlement' {} Text
a -> Entitlement
s {$sel:name:Entitlement' :: Text
name = Text
a} :: Entitlement)

-- | Entitlement unit.
entitlement_unit :: Lens.Lens' Entitlement EntitlementUnit
entitlement_unit :: (EntitlementUnit -> f EntitlementUnit)
-> Entitlement -> f Entitlement
entitlement_unit = (Entitlement -> EntitlementUnit)
-> (Entitlement -> EntitlementUnit -> Entitlement)
-> Lens Entitlement Entitlement EntitlementUnit EntitlementUnit
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entitlement' {EntitlementUnit
unit :: EntitlementUnit
$sel:unit:Entitlement' :: Entitlement -> EntitlementUnit
unit} -> EntitlementUnit
unit) (\s :: Entitlement
s@Entitlement' {} EntitlementUnit
a -> Entitlement
s {$sel:unit:Entitlement' :: EntitlementUnit
unit = EntitlementUnit
a} :: Entitlement)

instance Core.FromJSON Entitlement where
  parseJSON :: Value -> Parser Entitlement
parseJSON =
    String
-> (Object -> Parser Entitlement) -> Value -> Parser Entitlement
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Entitlement"
      ( \Object
x ->
          Maybe Integer
-> Maybe Text
-> Maybe Bool
-> Maybe Bool
-> Text
-> EntitlementUnit
-> Entitlement
Entitlement'
            (Maybe Integer
 -> Maybe Text
 -> Maybe Bool
 -> Maybe Bool
 -> Text
 -> EntitlementUnit
 -> Entitlement)
-> Parser (Maybe Integer)
-> Parser
     (Maybe Text
      -> Maybe Bool
      -> Maybe Bool
      -> Text
      -> EntitlementUnit
      -> Entitlement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MaxCount")
            Parser
  (Maybe Text
   -> Maybe Bool
   -> Maybe Bool
   -> Text
   -> EntitlementUnit
   -> Entitlement)
-> Parser (Maybe Text)
-> Parser
     (Maybe Bool
      -> Maybe Bool -> Text -> EntitlementUnit -> Entitlement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Value")
            Parser
  (Maybe Bool
   -> Maybe Bool -> Text -> EntitlementUnit -> Entitlement)
-> Parser (Maybe Bool)
-> Parser (Maybe Bool -> Text -> EntitlementUnit -> Entitlement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Overage")
            Parser (Maybe Bool -> Text -> EntitlementUnit -> Entitlement)
-> Parser (Maybe Bool)
-> Parser (Text -> EntitlementUnit -> Entitlement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AllowCheckIn")
            Parser (Text -> EntitlementUnit -> Entitlement)
-> Parser Text -> Parser (EntitlementUnit -> Entitlement)
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
"Name")
            Parser (EntitlementUnit -> Entitlement)
-> Parser EntitlementUnit -> Parser Entitlement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser EntitlementUnit
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Unit")
      )

instance Prelude.Hashable Entitlement

instance Prelude.NFData Entitlement

instance Core.ToJSON Entitlement where
  toJSON :: Entitlement -> Value
toJSON Entitlement' {Maybe Bool
Maybe Integer
Maybe Text
Text
EntitlementUnit
unit :: EntitlementUnit
name :: Text
allowCheckIn :: Maybe Bool
overage :: Maybe Bool
value :: Maybe Text
maxCount :: Maybe Integer
$sel:unit:Entitlement' :: Entitlement -> EntitlementUnit
$sel:name:Entitlement' :: Entitlement -> Text
$sel:allowCheckIn:Entitlement' :: Entitlement -> Maybe Bool
$sel:overage:Entitlement' :: Entitlement -> Maybe Bool
$sel:value:Entitlement' :: Entitlement -> Maybe Text
$sel:maxCount:Entitlement' :: Entitlement -> Maybe Integer
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"MaxCount" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
maxCount,
            (Text
"Value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
value,
            (Text
"Overage" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
overage,
            (Text
"AllowCheckIn" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
allowCheckIn,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Unit" Text -> EntitlementUnit -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= EntitlementUnit
unit)
          ]
      )