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

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

-- | A structure containing the identity provider (IdP) metadata used to
-- integrate the identity provider with this workspace. You can specify the
-- metadata either by providing a URL to its location in the @url@
-- parameter, or by specifying the full metadata in XML format in the @xml@
-- parameter. Specifying both will cause an error.
--
-- /See:/ 'newIdpMetadata' smart constructor.
data IdpMetadata = IdpMetadata'
  { -- | The URL of the location containing the IdP metadata.
    IdpMetadata -> Maybe Text
url :: Prelude.Maybe Prelude.Text,
    -- | The full IdP metadata, in XML format.
    IdpMetadata -> Maybe Text
xml :: Prelude.Maybe Prelude.Text
  }
  deriving (IdpMetadata -> IdpMetadata -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IdpMetadata -> IdpMetadata -> Bool
$c/= :: IdpMetadata -> IdpMetadata -> Bool
== :: IdpMetadata -> IdpMetadata -> Bool
$c== :: IdpMetadata -> IdpMetadata -> Bool
Prelude.Eq, ReadPrec [IdpMetadata]
ReadPrec IdpMetadata
Int -> ReadS IdpMetadata
ReadS [IdpMetadata]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IdpMetadata]
$creadListPrec :: ReadPrec [IdpMetadata]
readPrec :: ReadPrec IdpMetadata
$creadPrec :: ReadPrec IdpMetadata
readList :: ReadS [IdpMetadata]
$creadList :: ReadS [IdpMetadata]
readsPrec :: Int -> ReadS IdpMetadata
$creadsPrec :: Int -> ReadS IdpMetadata
Prelude.Read, Int -> IdpMetadata -> ShowS
[IdpMetadata] -> ShowS
IdpMetadata -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IdpMetadata] -> ShowS
$cshowList :: [IdpMetadata] -> ShowS
show :: IdpMetadata -> String
$cshow :: IdpMetadata -> String
showsPrec :: Int -> IdpMetadata -> ShowS
$cshowsPrec :: Int -> IdpMetadata -> ShowS
Prelude.Show, forall x. Rep IdpMetadata x -> IdpMetadata
forall x. IdpMetadata -> Rep IdpMetadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IdpMetadata x -> IdpMetadata
$cfrom :: forall x. IdpMetadata -> Rep IdpMetadata x
Prelude.Generic)

-- |
-- Create a value of 'IdpMetadata' 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:
--
-- 'url', 'idpMetadata_url' - The URL of the location containing the IdP metadata.
--
-- 'xml', 'idpMetadata_xml' - The full IdP metadata, in XML format.
newIdpMetadata ::
  IdpMetadata
newIdpMetadata :: IdpMetadata
newIdpMetadata =
  IdpMetadata'
    { $sel:url:IdpMetadata' :: Maybe Text
url = forall a. Maybe a
Prelude.Nothing,
      $sel:xml:IdpMetadata' :: Maybe Text
xml = forall a. Maybe a
Prelude.Nothing
    }

-- | The URL of the location containing the IdP metadata.
idpMetadata_url :: Lens.Lens' IdpMetadata (Prelude.Maybe Prelude.Text)
idpMetadata_url :: Lens' IdpMetadata (Maybe Text)
idpMetadata_url = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IdpMetadata' {Maybe Text
url :: Maybe Text
$sel:url:IdpMetadata' :: IdpMetadata -> Maybe Text
url} -> Maybe Text
url) (\s :: IdpMetadata
s@IdpMetadata' {} Maybe Text
a -> IdpMetadata
s {$sel:url:IdpMetadata' :: Maybe Text
url = Maybe Text
a} :: IdpMetadata)

-- | The full IdP metadata, in XML format.
idpMetadata_xml :: Lens.Lens' IdpMetadata (Prelude.Maybe Prelude.Text)
idpMetadata_xml :: Lens' IdpMetadata (Maybe Text)
idpMetadata_xml = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IdpMetadata' {Maybe Text
xml :: Maybe Text
$sel:xml:IdpMetadata' :: IdpMetadata -> Maybe Text
xml} -> Maybe Text
xml) (\s :: IdpMetadata
s@IdpMetadata' {} Maybe Text
a -> IdpMetadata
s {$sel:xml:IdpMetadata' :: Maybe Text
xml = Maybe Text
a} :: IdpMetadata)

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

instance Prelude.Hashable IdpMetadata where
  hashWithSalt :: Int -> IdpMetadata -> Int
hashWithSalt Int
_salt IdpMetadata' {Maybe Text
xml :: Maybe Text
url :: Maybe Text
$sel:xml:IdpMetadata' :: IdpMetadata -> Maybe Text
$sel:url:IdpMetadata' :: IdpMetadata -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
url
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
xml

instance Prelude.NFData IdpMetadata where
  rnf :: IdpMetadata -> ()
rnf IdpMetadata' {Maybe Text
xml :: Maybe Text
url :: Maybe Text
$sel:xml:IdpMetadata' :: IdpMetadata -> Maybe Text
$sel:url:IdpMetadata' :: IdpMetadata -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
url seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
xml

instance Data.ToJSON IdpMetadata where
  toJSON :: IdpMetadata -> Value
toJSON IdpMetadata' {Maybe Text
xml :: Maybe Text
url :: Maybe Text
$sel:xml:IdpMetadata' :: IdpMetadata -> Maybe Text
$sel:url:IdpMetadata' :: IdpMetadata -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"url" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
url,
            (Key
"xml" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
xml
          ]
      )