{-# 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.Grafana.Types.User
-- 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.Grafana.Types.User where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Grafana.Types.UserType
import qualified Amazonka.Prelude as Prelude

-- | A structure that specifies one user or group in the workspace.
--
-- /See:/ 'newUser' smart constructor.
data User = User'
  { -- | The ID of the user or group.
    --
    -- Pattern:
    -- @^([0-9a-fA-F]{10}-|)[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}$@
    User -> Text
id :: Prelude.Text,
    -- | Specifies whether this is a single user or a group.
    User -> UserType
type' :: UserType
  }
  deriving (User -> User -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: User -> User -> Bool
$c/= :: User -> User -> Bool
== :: User -> User -> Bool
$c== :: User -> User -> Bool
Prelude.Eq, ReadPrec [User]
ReadPrec User
Int -> ReadS User
ReadS [User]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [User]
$creadListPrec :: ReadPrec [User]
readPrec :: ReadPrec User
$creadPrec :: ReadPrec User
readList :: ReadS [User]
$creadList :: ReadS [User]
readsPrec :: Int -> ReadS User
$creadsPrec :: Int -> ReadS User
Prelude.Read, Int -> User -> ShowS
[User] -> ShowS
User -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [User] -> ShowS
$cshowList :: [User] -> ShowS
show :: User -> String
$cshow :: User -> String
showsPrec :: Int -> User -> ShowS
$cshowsPrec :: Int -> User -> ShowS
Prelude.Show, forall x. Rep User x -> User
forall x. User -> Rep User x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep User x -> User
$cfrom :: forall x. User -> Rep User x
Prelude.Generic)

-- |
-- Create a value of 'User' 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:
--
-- 'id', 'user_id' - The ID of the user or group.
--
-- Pattern:
-- @^([0-9a-fA-F]{10}-|)[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}$@
--
-- 'type'', 'user_type' - Specifies whether this is a single user or a group.
newUser ::
  -- | 'id'
  Prelude.Text ->
  -- | 'type''
  UserType ->
  User
newUser :: Text -> UserType -> User
newUser Text
pId_ UserType
pType_ =
  User' {$sel:id:User' :: Text
id = Text
pId_, $sel:type':User' :: UserType
type' = UserType
pType_}

-- | The ID of the user or group.
--
-- Pattern:
-- @^([0-9a-fA-F]{10}-|)[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}$@
user_id :: Lens.Lens' User Prelude.Text
user_id :: Lens' User Text
user_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {Text
id :: Text
$sel:id:User' :: User -> Text
id} -> Text
id) (\s :: User
s@User' {} Text
a -> User
s {$sel:id:User' :: Text
id = Text
a} :: User)

-- | Specifies whether this is a single user or a group.
user_type :: Lens.Lens' User UserType
user_type :: Lens' User UserType
user_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\User' {UserType
type' :: UserType
$sel:type':User' :: User -> UserType
type'} -> UserType
type') (\s :: User
s@User' {} UserType
a -> User
s {$sel:type':User' :: UserType
type' = UserType
a} :: User)

instance Data.FromJSON User where
  parseJSON :: Value -> Parser User
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"User"
      ( \Object
x ->
          Text -> UserType -> User
User'
            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
"id")
            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
"type")
      )

instance Prelude.Hashable User where
  hashWithSalt :: Int -> User -> Int
hashWithSalt Int
_salt User' {Text
UserType
type' :: UserType
id :: Text
$sel:type':User' :: User -> UserType
$sel:id:User' :: User -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` UserType
type'

instance Prelude.NFData User where
  rnf :: User -> ()
rnf User' {Text
UserType
type' :: UserType
id :: Text
$sel:type':User' :: User -> UserType
$sel:id:User' :: User -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
id seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf UserType
type'

instance Data.ToJSON User where
  toJSON :: User -> Value
toJSON User' {Text
UserType
type' :: UserType
id :: Text
$sel:type':User' :: User -> UserType
$sel:id:User' :: User -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"id" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
id),
            forall a. a -> Maybe a
Prelude.Just (Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= UserType
type')
          ]
      )