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

import qualified Amazonka.Core as Core
import Amazonka.Grafana.Types.UserType
import qualified Amazonka.Lens as Lens
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.
    User -> Text
id :: Prelude.Text,
    -- | Specifies whether this is a single user or a group.
    User -> UserType
type' :: UserType
  }
  deriving (User -> User -> Bool
(User -> User -> Bool) -> (User -> User -> Bool) -> Eq User
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]
(Int -> ReadS User)
-> ReadS [User] -> ReadPrec User -> ReadPrec [User] -> Read 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
(Int -> User -> ShowS)
-> (User -> String) -> ([User] -> ShowS) -> Show User
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. User -> Rep User x)
-> (forall x. Rep User x -> User) -> Generic User
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.
--
-- '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' :: Text -> UserType -> User
User' {$sel:id:User' :: Text
id = Text
pId_, $sel:type':User' :: UserType
type' = UserType
pType_}

-- | The ID of the user or group.
user_id :: Lens.Lens' User Prelude.Text
user_id :: (Text -> f Text) -> User -> f User
user_id = (User -> Text)
-> (User -> Text -> User) -> Lens User User Text Text
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 :: (UserType -> f UserType) -> User -> f User
user_type = (User -> UserType)
-> (User -> UserType -> User) -> Lens User User UserType UserType
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 Core.FromJSON User where
  parseJSON :: Value -> Parser User
parseJSON =
    String -> (Object -> Parser User) -> Value -> Parser User
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"User"
      ( \Object
x ->
          Text -> UserType -> User
User'
            (Text -> UserType -> User)
-> Parser Text -> Parser (UserType -> User)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"id") Parser (UserType -> User) -> Parser UserType -> Parser User
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser UserType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"type")
      )

instance Prelude.Hashable User

instance Prelude.NFData User

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> UserType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= UserType
type')
          ]
      )