{-# 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.ElasticSearch.Types.AuthorizedPrincipal
-- 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.ElasticSearch.Types.AuthorizedPrincipal where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ElasticSearch.Types.PrincipalType
import qualified Amazonka.Prelude as Prelude

-- | Information about an account or service that has access to an Amazon
-- OpenSearch Service domain through the use of an interface VPC endpoint.
--
-- /See:/ 'newAuthorizedPrincipal' smart constructor.
data AuthorizedPrincipal = AuthorizedPrincipal'
  { -- | The IAM principal that is allowed access to the domain.
    AuthorizedPrincipal -> Maybe Text
principal :: Prelude.Maybe Prelude.Text,
    -- | The type of principal.
    AuthorizedPrincipal -> Maybe PrincipalType
principalType :: Prelude.Maybe PrincipalType
  }
  deriving (AuthorizedPrincipal -> AuthorizedPrincipal -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AuthorizedPrincipal -> AuthorizedPrincipal -> Bool
$c/= :: AuthorizedPrincipal -> AuthorizedPrincipal -> Bool
== :: AuthorizedPrincipal -> AuthorizedPrincipal -> Bool
$c== :: AuthorizedPrincipal -> AuthorizedPrincipal -> Bool
Prelude.Eq, ReadPrec [AuthorizedPrincipal]
ReadPrec AuthorizedPrincipal
Int -> ReadS AuthorizedPrincipal
ReadS [AuthorizedPrincipal]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AuthorizedPrincipal]
$creadListPrec :: ReadPrec [AuthorizedPrincipal]
readPrec :: ReadPrec AuthorizedPrincipal
$creadPrec :: ReadPrec AuthorizedPrincipal
readList :: ReadS [AuthorizedPrincipal]
$creadList :: ReadS [AuthorizedPrincipal]
readsPrec :: Int -> ReadS AuthorizedPrincipal
$creadsPrec :: Int -> ReadS AuthorizedPrincipal
Prelude.Read, Int -> AuthorizedPrincipal -> ShowS
[AuthorizedPrincipal] -> ShowS
AuthorizedPrincipal -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuthorizedPrincipal] -> ShowS
$cshowList :: [AuthorizedPrincipal] -> ShowS
show :: AuthorizedPrincipal -> String
$cshow :: AuthorizedPrincipal -> String
showsPrec :: Int -> AuthorizedPrincipal -> ShowS
$cshowsPrec :: Int -> AuthorizedPrincipal -> ShowS
Prelude.Show, forall x. Rep AuthorizedPrincipal x -> AuthorizedPrincipal
forall x. AuthorizedPrincipal -> Rep AuthorizedPrincipal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AuthorizedPrincipal x -> AuthorizedPrincipal
$cfrom :: forall x. AuthorizedPrincipal -> Rep AuthorizedPrincipal x
Prelude.Generic)

-- |
-- Create a value of 'AuthorizedPrincipal' 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:
--
-- 'principal', 'authorizedPrincipal_principal' - The IAM principal that is allowed access to the domain.
--
-- 'principalType', 'authorizedPrincipal_principalType' - The type of principal.
newAuthorizedPrincipal ::
  AuthorizedPrincipal
newAuthorizedPrincipal :: AuthorizedPrincipal
newAuthorizedPrincipal =
  AuthorizedPrincipal'
    { $sel:principal:AuthorizedPrincipal' :: Maybe Text
principal = forall a. Maybe a
Prelude.Nothing,
      $sel:principalType:AuthorizedPrincipal' :: Maybe PrincipalType
principalType = forall a. Maybe a
Prelude.Nothing
    }

-- | The IAM principal that is allowed access to the domain.
authorizedPrincipal_principal :: Lens.Lens' AuthorizedPrincipal (Prelude.Maybe Prelude.Text)
authorizedPrincipal_principal :: Lens' AuthorizedPrincipal (Maybe Text)
authorizedPrincipal_principal = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthorizedPrincipal' {Maybe Text
principal :: Maybe Text
$sel:principal:AuthorizedPrincipal' :: AuthorizedPrincipal -> Maybe Text
principal} -> Maybe Text
principal) (\s :: AuthorizedPrincipal
s@AuthorizedPrincipal' {} Maybe Text
a -> AuthorizedPrincipal
s {$sel:principal:AuthorizedPrincipal' :: Maybe Text
principal = Maybe Text
a} :: AuthorizedPrincipal)

-- | The type of principal.
authorizedPrincipal_principalType :: Lens.Lens' AuthorizedPrincipal (Prelude.Maybe PrincipalType)
authorizedPrincipal_principalType :: Lens' AuthorizedPrincipal (Maybe PrincipalType)
authorizedPrincipal_principalType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthorizedPrincipal' {Maybe PrincipalType
principalType :: Maybe PrincipalType
$sel:principalType:AuthorizedPrincipal' :: AuthorizedPrincipal -> Maybe PrincipalType
principalType} -> Maybe PrincipalType
principalType) (\s :: AuthorizedPrincipal
s@AuthorizedPrincipal' {} Maybe PrincipalType
a -> AuthorizedPrincipal
s {$sel:principalType:AuthorizedPrincipal' :: Maybe PrincipalType
principalType = Maybe PrincipalType
a} :: AuthorizedPrincipal)

instance Data.FromJSON AuthorizedPrincipal where
  parseJSON :: Value -> Parser AuthorizedPrincipal
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AuthorizedPrincipal"
      ( \Object
x ->
          Maybe Text -> Maybe PrincipalType -> AuthorizedPrincipal
AuthorizedPrincipal'
            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
"Principal")
            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
"PrincipalType")
      )

instance Prelude.Hashable AuthorizedPrincipal where
  hashWithSalt :: Int -> AuthorizedPrincipal -> Int
hashWithSalt Int
_salt AuthorizedPrincipal' {Maybe Text
Maybe PrincipalType
principalType :: Maybe PrincipalType
principal :: Maybe Text
$sel:principalType:AuthorizedPrincipal' :: AuthorizedPrincipal -> Maybe PrincipalType
$sel:principal:AuthorizedPrincipal' :: AuthorizedPrincipal -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
principal
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe PrincipalType
principalType

instance Prelude.NFData AuthorizedPrincipal where
  rnf :: AuthorizedPrincipal -> ()
rnf AuthorizedPrincipal' {Maybe Text
Maybe PrincipalType
principalType :: Maybe PrincipalType
principal :: Maybe Text
$sel:principalType:AuthorizedPrincipal' :: AuthorizedPrincipal -> Maybe PrincipalType
$sel:principal:AuthorizedPrincipal' :: AuthorizedPrincipal -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
principal
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe PrincipalType
principalType