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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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'
  { -- | Indicates whether check-ins are allowed.
    Entitlement -> Maybe Bool
allowCheckIn :: Prelude.Maybe Prelude.Bool,
    -- | Maximum entitlement count. Use if the unit is not None.
    Entitlement -> Maybe Integer
maxCount :: Prelude.Maybe Prelude.Integer,
    -- | Indicates whether overages are allowed.
    Entitlement -> Maybe Bool
overage :: Prelude.Maybe Prelude.Bool,
    -- | Entitlement resource. Use only if the unit is None.
    Entitlement -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | Entitlement name.
    Entitlement -> Text
name :: Prelude.Text,
    -- | Entitlement unit.
    Entitlement -> EntitlementUnit
unit :: EntitlementUnit
  }
  deriving (Entitlement -> Entitlement -> Bool
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]
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
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. 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:
--
-- 'allowCheckIn', 'entitlement_allowCheckIn' - Indicates whether check-ins are allowed.
--
-- 'maxCount', 'entitlement_maxCount' - Maximum entitlement count. Use if the unit is not None.
--
-- 'overage', 'entitlement_overage' - Indicates whether overages are allowed.
--
-- 'value', 'entitlement_value' - Entitlement resource. Use only if the unit is None.
--
-- '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'
    { $sel:allowCheckIn:Entitlement' :: Maybe Bool
allowCheckIn = forall a. Maybe a
Prelude.Nothing,
      $sel:maxCount:Entitlement' :: Maybe Integer
maxCount = forall a. Maybe a
Prelude.Nothing,
      $sel:overage:Entitlement' :: Maybe Bool
overage = forall a. Maybe a
Prelude.Nothing,
      $sel:value:Entitlement' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing,
      $sel:name:Entitlement' :: Text
name = Text
pName_,
      $sel:unit:Entitlement' :: EntitlementUnit
unit = EntitlementUnit
pUnit_
    }

-- | Indicates whether check-ins are allowed.
entitlement_allowCheckIn :: Lens.Lens' Entitlement (Prelude.Maybe Prelude.Bool)
entitlement_allowCheckIn :: Lens' Entitlement (Maybe Bool)
entitlement_allowCheckIn = 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)

-- | Maximum entitlement count. Use if the unit is not None.
entitlement_maxCount :: Lens.Lens' Entitlement (Prelude.Maybe Prelude.Integer)
entitlement_maxCount :: Lens' Entitlement (Maybe Integer)
entitlement_maxCount = 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)

-- | Indicates whether overages are allowed.
entitlement_overage :: Lens.Lens' Entitlement (Prelude.Maybe Prelude.Bool)
entitlement_overage :: Lens' Entitlement (Maybe Bool)
entitlement_overage = 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)

-- | Entitlement resource. Use only if the unit is None.
entitlement_value :: Lens.Lens' Entitlement (Prelude.Maybe Prelude.Text)
entitlement_value :: Lens' Entitlement (Maybe Text)
entitlement_value = 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)

-- | Entitlement name.
entitlement_name :: Lens.Lens' Entitlement Prelude.Text
entitlement_name :: Lens' Entitlement Text
entitlement_name = 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 :: Lens' Entitlement EntitlementUnit
entitlement_unit = 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 Data.FromJSON Entitlement where
  parseJSON :: Value -> Parser Entitlement
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Entitlement"
      ( \Object
x ->
          Maybe Bool
-> Maybe Integer
-> Maybe Bool
-> Maybe Text
-> Text
-> EntitlementUnit
-> Entitlement
Entitlement'
            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
"AllowCheckIn")
            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
"MaxCount")
            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
"Overage")
            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
"Value")
            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
"Name")
            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
"Unit")
      )

instance Prelude.Hashable Entitlement where
  hashWithSalt :: Int -> Entitlement -> Int
hashWithSalt Int
_salt Entitlement' {Maybe Bool
Maybe Integer
Maybe Text
Text
EntitlementUnit
unit :: EntitlementUnit
name :: Text
value :: Maybe Text
overage :: Maybe Bool
maxCount :: Maybe Integer
allowCheckIn :: Maybe Bool
$sel:unit:Entitlement' :: Entitlement -> EntitlementUnit
$sel:name:Entitlement' :: Entitlement -> Text
$sel:value:Entitlement' :: Entitlement -> Maybe Text
$sel:overage:Entitlement' :: Entitlement -> Maybe Bool
$sel:maxCount:Entitlement' :: Entitlement -> Maybe Integer
$sel:allowCheckIn:Entitlement' :: Entitlement -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
allowCheckIn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
maxCount
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
overage
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` EntitlementUnit
unit

instance Prelude.NFData Entitlement where
  rnf :: Entitlement -> ()
rnf Entitlement' {Maybe Bool
Maybe Integer
Maybe Text
Text
EntitlementUnit
unit :: EntitlementUnit
name :: Text
value :: Maybe Text
overage :: Maybe Bool
maxCount :: Maybe Integer
allowCheckIn :: Maybe Bool
$sel:unit:Entitlement' :: Entitlement -> EntitlementUnit
$sel:name:Entitlement' :: Entitlement -> Text
$sel:value:Entitlement' :: Entitlement -> Maybe Text
$sel:overage:Entitlement' :: Entitlement -> Maybe Bool
$sel:maxCount:Entitlement' :: Entitlement -> Maybe Integer
$sel:allowCheckIn:Entitlement' :: Entitlement -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
allowCheckIn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
maxCount
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
overage
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf EntitlementUnit
unit

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