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

import Amazonka.AppStream.Types.AppVisibility
import Amazonka.AppStream.Types.EntitlementAttribute
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Specifies an entitlement. Entitlements control access to specific
-- applications within a stack, based on user attributes. Entitlements
-- apply to SAML 2.0 federated user identities. Amazon AppStream 2.0 user
-- pool and streaming URL users are entitled to all applications in a
-- stack. Entitlements don\'t apply to the desktop stream view application,
-- or to applications managed by a dynamic app provider using the Dynamic
-- Application Framework.
--
-- /See:/ 'newEntitlement' smart constructor.
data Entitlement = Entitlement'
  { -- | The time when the entitlement was created.
    Entitlement -> Maybe POSIX
createdTime :: Prelude.Maybe Data.POSIX,
    -- | The description of the entitlement.
    Entitlement -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The time when the entitlement was last modified.
    Entitlement -> Maybe POSIX
lastModifiedTime :: Prelude.Maybe Data.POSIX,
    -- | The name of the entitlement.
    Entitlement -> Text
name :: Prelude.Text,
    -- | The name of the stack with which the entitlement is associated.
    Entitlement -> Text
stackName :: Prelude.Text,
    -- | Specifies whether all or selected apps are entitled.
    Entitlement -> AppVisibility
appVisibility :: AppVisibility,
    -- | The attributes of the entitlement.
    Entitlement -> NonEmpty EntitlementAttribute
attributes :: Prelude.NonEmpty EntitlementAttribute
  }
  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:
--
-- 'createdTime', 'entitlement_createdTime' - The time when the entitlement was created.
--
-- 'description', 'entitlement_description' - The description of the entitlement.
--
-- 'lastModifiedTime', 'entitlement_lastModifiedTime' - The time when the entitlement was last modified.
--
-- 'name', 'entitlement_name' - The name of the entitlement.
--
-- 'stackName', 'entitlement_stackName' - The name of the stack with which the entitlement is associated.
--
-- 'appVisibility', 'entitlement_appVisibility' - Specifies whether all or selected apps are entitled.
--
-- 'attributes', 'entitlement_attributes' - The attributes of the entitlement.
newEntitlement ::
  -- | 'name'
  Prelude.Text ->
  -- | 'stackName'
  Prelude.Text ->
  -- | 'appVisibility'
  AppVisibility ->
  -- | 'attributes'
  Prelude.NonEmpty EntitlementAttribute ->
  Entitlement
newEntitlement :: Text
-> Text
-> AppVisibility
-> NonEmpty EntitlementAttribute
-> Entitlement
newEntitlement
  Text
pName_
  Text
pStackName_
  AppVisibility
pAppVisibility_
  NonEmpty EntitlementAttribute
pAttributes_ =
    Entitlement'
      { $sel:createdTime:Entitlement' :: Maybe POSIX
createdTime = forall a. Maybe a
Prelude.Nothing,
        $sel:description:Entitlement' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
        $sel:lastModifiedTime:Entitlement' :: Maybe POSIX
lastModifiedTime = forall a. Maybe a
Prelude.Nothing,
        $sel:name:Entitlement' :: Text
name = Text
pName_,
        $sel:stackName:Entitlement' :: Text
stackName = Text
pStackName_,
        $sel:appVisibility:Entitlement' :: AppVisibility
appVisibility = AppVisibility
pAppVisibility_,
        $sel:attributes:Entitlement' :: NonEmpty EntitlementAttribute
attributes = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty EntitlementAttribute
pAttributes_
      }

-- | The time when the entitlement was created.
entitlement_createdTime :: Lens.Lens' Entitlement (Prelude.Maybe Prelude.UTCTime)
entitlement_createdTime :: Lens' Entitlement (Maybe UTCTime)
entitlement_createdTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entitlement' {Maybe POSIX
createdTime :: Maybe POSIX
$sel:createdTime:Entitlement' :: Entitlement -> Maybe POSIX
createdTime} -> Maybe POSIX
createdTime) (\s :: Entitlement
s@Entitlement' {} Maybe POSIX
a -> Entitlement
s {$sel:createdTime:Entitlement' :: Maybe POSIX
createdTime = Maybe POSIX
a} :: Entitlement) 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 description of the entitlement.
entitlement_description :: Lens.Lens' Entitlement (Prelude.Maybe Prelude.Text)
entitlement_description :: Lens' Entitlement (Maybe Text)
entitlement_description = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entitlement' {Maybe Text
description :: Maybe Text
$sel:description:Entitlement' :: Entitlement -> Maybe Text
description} -> Maybe Text
description) (\s :: Entitlement
s@Entitlement' {} Maybe Text
a -> Entitlement
s {$sel:description:Entitlement' :: Maybe Text
description = Maybe Text
a} :: Entitlement)

-- | The time when the entitlement was last modified.
entitlement_lastModifiedTime :: Lens.Lens' Entitlement (Prelude.Maybe Prelude.UTCTime)
entitlement_lastModifiedTime :: Lens' Entitlement (Maybe UTCTime)
entitlement_lastModifiedTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entitlement' {Maybe POSIX
lastModifiedTime :: Maybe POSIX
$sel:lastModifiedTime:Entitlement' :: Entitlement -> Maybe POSIX
lastModifiedTime} -> Maybe POSIX
lastModifiedTime) (\s :: Entitlement
s@Entitlement' {} Maybe POSIX
a -> Entitlement
s {$sel:lastModifiedTime:Entitlement' :: Maybe POSIX
lastModifiedTime = Maybe POSIX
a} :: Entitlement) 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 name of the entitlement.
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)

-- | The name of the stack with which the entitlement is associated.
entitlement_stackName :: Lens.Lens' Entitlement Prelude.Text
entitlement_stackName :: Lens' Entitlement Text
entitlement_stackName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entitlement' {Text
stackName :: Text
$sel:stackName:Entitlement' :: Entitlement -> Text
stackName} -> Text
stackName) (\s :: Entitlement
s@Entitlement' {} Text
a -> Entitlement
s {$sel:stackName:Entitlement' :: Text
stackName = Text
a} :: Entitlement)

-- | Specifies whether all or selected apps are entitled.
entitlement_appVisibility :: Lens.Lens' Entitlement AppVisibility
entitlement_appVisibility :: Lens' Entitlement AppVisibility
entitlement_appVisibility = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entitlement' {AppVisibility
appVisibility :: AppVisibility
$sel:appVisibility:Entitlement' :: Entitlement -> AppVisibility
appVisibility} -> AppVisibility
appVisibility) (\s :: Entitlement
s@Entitlement' {} AppVisibility
a -> Entitlement
s {$sel:appVisibility:Entitlement' :: AppVisibility
appVisibility = AppVisibility
a} :: Entitlement)

-- | The attributes of the entitlement.
entitlement_attributes :: Lens.Lens' Entitlement (Prelude.NonEmpty EntitlementAttribute)
entitlement_attributes :: Lens' Entitlement (NonEmpty EntitlementAttribute)
entitlement_attributes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entitlement' {NonEmpty EntitlementAttribute
attributes :: NonEmpty EntitlementAttribute
$sel:attributes:Entitlement' :: Entitlement -> NonEmpty EntitlementAttribute
attributes} -> NonEmpty EntitlementAttribute
attributes) (\s :: Entitlement
s@Entitlement' {} NonEmpty EntitlementAttribute
a -> Entitlement
s {$sel:attributes:Entitlement' :: NonEmpty EntitlementAttribute
attributes = NonEmpty EntitlementAttribute
a} :: Entitlement) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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 POSIX
-> Maybe Text
-> Maybe POSIX
-> Text
-> Text
-> AppVisibility
-> NonEmpty EntitlementAttribute
-> 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
"CreatedTime")
            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
"Description")
            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
"LastModifiedTime")
            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
"StackName")
            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
"AppVisibility")
            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
"Attributes")
      )

instance Prelude.Hashable Entitlement where
  hashWithSalt :: Int -> Entitlement -> Int
hashWithSalt Int
_salt Entitlement' {Maybe Text
Maybe POSIX
NonEmpty EntitlementAttribute
Text
AppVisibility
attributes :: NonEmpty EntitlementAttribute
appVisibility :: AppVisibility
stackName :: Text
name :: Text
lastModifiedTime :: Maybe POSIX
description :: Maybe Text
createdTime :: Maybe POSIX
$sel:attributes:Entitlement' :: Entitlement -> NonEmpty EntitlementAttribute
$sel:appVisibility:Entitlement' :: Entitlement -> AppVisibility
$sel:stackName:Entitlement' :: Entitlement -> Text
$sel:name:Entitlement' :: Entitlement -> Text
$sel:lastModifiedTime:Entitlement' :: Entitlement -> Maybe POSIX
$sel:description:Entitlement' :: Entitlement -> Maybe Text
$sel:createdTime:Entitlement' :: Entitlement -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
createdTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
lastModifiedTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
stackName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` AppVisibility
appVisibility
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty EntitlementAttribute
attributes

instance Prelude.NFData Entitlement where
  rnf :: Entitlement -> ()
rnf Entitlement' {Maybe Text
Maybe POSIX
NonEmpty EntitlementAttribute
Text
AppVisibility
attributes :: NonEmpty EntitlementAttribute
appVisibility :: AppVisibility
stackName :: Text
name :: Text
lastModifiedTime :: Maybe POSIX
description :: Maybe Text
createdTime :: Maybe POSIX
$sel:attributes:Entitlement' :: Entitlement -> NonEmpty EntitlementAttribute
$sel:appVisibility:Entitlement' :: Entitlement -> AppVisibility
$sel:stackName:Entitlement' :: Entitlement -> Text
$sel:name:Entitlement' :: Entitlement -> Text
$sel:lastModifiedTime:Entitlement' :: Entitlement -> Maybe POSIX
$sel:description:Entitlement' :: Entitlement -> Maybe Text
$sel:createdTime:Entitlement' :: Entitlement -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
createdTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
lastModifiedTime
      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 Text
stackName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf AppVisibility
appVisibility
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty EntitlementAttribute
attributes