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

import Amazonka.AppStream.Types.Action
import Amazonka.AppStream.Types.Permission
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

-- | Describes an action and whether the action is enabled or disabled for
-- users during their streaming sessions.
--
-- /See:/ 'newUserSetting' smart constructor.
data UserSetting = UserSetting'
  { -- | The action that is enabled or disabled.
    UserSetting -> Action
action :: Action,
    -- | Indicates whether the action is enabled or disabled.
    UserSetting -> Permission
permission :: Permission
  }
  deriving (UserSetting -> UserSetting -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UserSetting -> UserSetting -> Bool
$c/= :: UserSetting -> UserSetting -> Bool
== :: UserSetting -> UserSetting -> Bool
$c== :: UserSetting -> UserSetting -> Bool
Prelude.Eq, ReadPrec [UserSetting]
ReadPrec UserSetting
Int -> ReadS UserSetting
ReadS [UserSetting]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UserSetting]
$creadListPrec :: ReadPrec [UserSetting]
readPrec :: ReadPrec UserSetting
$creadPrec :: ReadPrec UserSetting
readList :: ReadS [UserSetting]
$creadList :: ReadS [UserSetting]
readsPrec :: Int -> ReadS UserSetting
$creadsPrec :: Int -> ReadS UserSetting
Prelude.Read, Int -> UserSetting -> ShowS
[UserSetting] -> ShowS
UserSetting -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UserSetting] -> ShowS
$cshowList :: [UserSetting] -> ShowS
show :: UserSetting -> String
$cshow :: UserSetting -> String
showsPrec :: Int -> UserSetting -> ShowS
$cshowsPrec :: Int -> UserSetting -> ShowS
Prelude.Show, forall x. Rep UserSetting x -> UserSetting
forall x. UserSetting -> Rep UserSetting x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UserSetting x -> UserSetting
$cfrom :: forall x. UserSetting -> Rep UserSetting x
Prelude.Generic)

-- |
-- Create a value of 'UserSetting' 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:
--
-- 'action', 'userSetting_action' - The action that is enabled or disabled.
--
-- 'permission', 'userSetting_permission' - Indicates whether the action is enabled or disabled.
newUserSetting ::
  -- | 'action'
  Action ->
  -- | 'permission'
  Permission ->
  UserSetting
newUserSetting :: Action -> Permission -> UserSetting
newUserSetting Action
pAction_ Permission
pPermission_ =
  UserSetting'
    { $sel:action:UserSetting' :: Action
action = Action
pAction_,
      $sel:permission:UserSetting' :: Permission
permission = Permission
pPermission_
    }

-- | The action that is enabled or disabled.
userSetting_action :: Lens.Lens' UserSetting Action
userSetting_action :: Lens' UserSetting Action
userSetting_action = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserSetting' {Action
action :: Action
$sel:action:UserSetting' :: UserSetting -> Action
action} -> Action
action) (\s :: UserSetting
s@UserSetting' {} Action
a -> UserSetting
s {$sel:action:UserSetting' :: Action
action = Action
a} :: UserSetting)

-- | Indicates whether the action is enabled or disabled.
userSetting_permission :: Lens.Lens' UserSetting Permission
userSetting_permission :: Lens' UserSetting Permission
userSetting_permission = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserSetting' {Permission
permission :: Permission
$sel:permission:UserSetting' :: UserSetting -> Permission
permission} -> Permission
permission) (\s :: UserSetting
s@UserSetting' {} Permission
a -> UserSetting
s {$sel:permission:UserSetting' :: Permission
permission = Permission
a} :: UserSetting)

instance Data.FromJSON UserSetting where
  parseJSON :: Value -> Parser UserSetting
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"UserSetting"
      ( \Object
x ->
          Action -> Permission -> UserSetting
UserSetting'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Action")
            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
"Permission")
      )

instance Prelude.Hashable UserSetting where
  hashWithSalt :: Int -> UserSetting -> Int
hashWithSalt Int
_salt UserSetting' {Action
Permission
permission :: Permission
action :: Action
$sel:permission:UserSetting' :: UserSetting -> Permission
$sel:action:UserSetting' :: UserSetting -> Action
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Action
action
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Permission
permission

instance Prelude.NFData UserSetting where
  rnf :: UserSetting -> ()
rnf UserSetting' {Action
Permission
permission :: Permission
action :: Action
$sel:permission:UserSetting' :: UserSetting -> Permission
$sel:action:UserSetting' :: UserSetting -> Action
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Action
action
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Permission
permission

instance Data.ToJSON UserSetting where
  toJSON :: UserSetting -> Value
toJSON UserSetting' {Action
Permission
permission :: Permission
action :: Action
$sel:permission:UserSetting' :: UserSetting -> Permission
$sel:action:UserSetting' :: UserSetting -> Action
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Action" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Action
action),
            forall a. a -> Maybe a
Prelude.Just (Key
"Permission" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Permission
permission)
          ]
      )