{-# 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.Glue.Types.SchemaId
-- 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.Glue.Types.SchemaId where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The unique ID of the schema in the Glue schema registry.
--
-- /See:/ 'newSchemaId' smart constructor.
data SchemaId = SchemaId'
  { -- | The name of the schema registry that contains the schema.
    SchemaId -> Maybe Text
registryName :: Prelude.Maybe Prelude.Text,
    -- | The name of the schema. One of @SchemaArn@ or @SchemaName@ has to be
    -- provided.
    SchemaId -> Maybe Text
schemaName :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the schema. One of @SchemaArn@ or
    -- @SchemaName@ has to be provided.
    SchemaId -> Maybe Text
schemaArn :: Prelude.Maybe Prelude.Text
  }
  deriving (SchemaId -> SchemaId -> Bool
(SchemaId -> SchemaId -> Bool)
-> (SchemaId -> SchemaId -> Bool) -> Eq SchemaId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SchemaId -> SchemaId -> Bool
$c/= :: SchemaId -> SchemaId -> Bool
== :: SchemaId -> SchemaId -> Bool
$c== :: SchemaId -> SchemaId -> Bool
Prelude.Eq, ReadPrec [SchemaId]
ReadPrec SchemaId
Int -> ReadS SchemaId
ReadS [SchemaId]
(Int -> ReadS SchemaId)
-> ReadS [SchemaId]
-> ReadPrec SchemaId
-> ReadPrec [SchemaId]
-> Read SchemaId
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SchemaId]
$creadListPrec :: ReadPrec [SchemaId]
readPrec :: ReadPrec SchemaId
$creadPrec :: ReadPrec SchemaId
readList :: ReadS [SchemaId]
$creadList :: ReadS [SchemaId]
readsPrec :: Int -> ReadS SchemaId
$creadsPrec :: Int -> ReadS SchemaId
Prelude.Read, Int -> SchemaId -> ShowS
[SchemaId] -> ShowS
SchemaId -> String
(Int -> SchemaId -> ShowS)
-> (SchemaId -> String) -> ([SchemaId] -> ShowS) -> Show SchemaId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SchemaId] -> ShowS
$cshowList :: [SchemaId] -> ShowS
show :: SchemaId -> String
$cshow :: SchemaId -> String
showsPrec :: Int -> SchemaId -> ShowS
$cshowsPrec :: Int -> SchemaId -> ShowS
Prelude.Show, (forall x. SchemaId -> Rep SchemaId x)
-> (forall x. Rep SchemaId x -> SchemaId) -> Generic SchemaId
forall x. Rep SchemaId x -> SchemaId
forall x. SchemaId -> Rep SchemaId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SchemaId x -> SchemaId
$cfrom :: forall x. SchemaId -> Rep SchemaId x
Prelude.Generic)

-- |
-- Create a value of 'SchemaId' 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:
--
-- 'registryName', 'schemaId_registryName' - The name of the schema registry that contains the schema.
--
-- 'schemaName', 'schemaId_schemaName' - The name of the schema. One of @SchemaArn@ or @SchemaName@ has to be
-- provided.
--
-- 'schemaArn', 'schemaId_schemaArn' - The Amazon Resource Name (ARN) of the schema. One of @SchemaArn@ or
-- @SchemaName@ has to be provided.
newSchemaId ::
  SchemaId
newSchemaId :: SchemaId
newSchemaId =
  SchemaId' :: Maybe Text -> Maybe Text -> Maybe Text -> SchemaId
SchemaId'
    { $sel:registryName:SchemaId' :: Maybe Text
registryName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:schemaName:SchemaId' :: Maybe Text
schemaName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:schemaArn:SchemaId' :: Maybe Text
schemaArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the schema registry that contains the schema.
schemaId_registryName :: Lens.Lens' SchemaId (Prelude.Maybe Prelude.Text)
schemaId_registryName :: (Maybe Text -> f (Maybe Text)) -> SchemaId -> f SchemaId
schemaId_registryName = (SchemaId -> Maybe Text)
-> (SchemaId -> Maybe Text -> SchemaId)
-> Lens SchemaId SchemaId (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SchemaId' {Maybe Text
registryName :: Maybe Text
$sel:registryName:SchemaId' :: SchemaId -> Maybe Text
registryName} -> Maybe Text
registryName) (\s :: SchemaId
s@SchemaId' {} Maybe Text
a -> SchemaId
s {$sel:registryName:SchemaId' :: Maybe Text
registryName = Maybe Text
a} :: SchemaId)

-- | The name of the schema. One of @SchemaArn@ or @SchemaName@ has to be
-- provided.
schemaId_schemaName :: Lens.Lens' SchemaId (Prelude.Maybe Prelude.Text)
schemaId_schemaName :: (Maybe Text -> f (Maybe Text)) -> SchemaId -> f SchemaId
schemaId_schemaName = (SchemaId -> Maybe Text)
-> (SchemaId -> Maybe Text -> SchemaId)
-> Lens SchemaId SchemaId (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SchemaId' {Maybe Text
schemaName :: Maybe Text
$sel:schemaName:SchemaId' :: SchemaId -> Maybe Text
schemaName} -> Maybe Text
schemaName) (\s :: SchemaId
s@SchemaId' {} Maybe Text
a -> SchemaId
s {$sel:schemaName:SchemaId' :: Maybe Text
schemaName = Maybe Text
a} :: SchemaId)

-- | The Amazon Resource Name (ARN) of the schema. One of @SchemaArn@ or
-- @SchemaName@ has to be provided.
schemaId_schemaArn :: Lens.Lens' SchemaId (Prelude.Maybe Prelude.Text)
schemaId_schemaArn :: (Maybe Text -> f (Maybe Text)) -> SchemaId -> f SchemaId
schemaId_schemaArn = (SchemaId -> Maybe Text)
-> (SchemaId -> Maybe Text -> SchemaId)
-> Lens SchemaId SchemaId (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SchemaId' {Maybe Text
schemaArn :: Maybe Text
$sel:schemaArn:SchemaId' :: SchemaId -> Maybe Text
schemaArn} -> Maybe Text
schemaArn) (\s :: SchemaId
s@SchemaId' {} Maybe Text
a -> SchemaId
s {$sel:schemaArn:SchemaId' :: Maybe Text
schemaArn = Maybe Text
a} :: SchemaId)

instance Core.FromJSON SchemaId where
  parseJSON :: Value -> Parser SchemaId
parseJSON =
    String -> (Object -> Parser SchemaId) -> Value -> Parser SchemaId
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SchemaId"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Maybe Text -> SchemaId
SchemaId'
            (Maybe Text -> Maybe Text -> Maybe Text -> SchemaId)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> SchemaId)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RegistryName")
            Parser (Maybe Text -> Maybe Text -> SchemaId)
-> Parser (Maybe Text) -> Parser (Maybe Text -> SchemaId)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SchemaName")
            Parser (Maybe Text -> SchemaId)
-> Parser (Maybe Text) -> Parser SchemaId
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SchemaArn")
      )

instance Prelude.Hashable SchemaId

instance Prelude.NFData SchemaId

instance Core.ToJSON SchemaId where
  toJSON :: SchemaId -> Value
toJSON SchemaId' {Maybe Text
schemaArn :: Maybe Text
schemaName :: Maybe Text
registryName :: Maybe Text
$sel:schemaArn:SchemaId' :: SchemaId -> Maybe Text
$sel:schemaName:SchemaId' :: SchemaId -> Maybe Text
$sel:registryName:SchemaId' :: SchemaId -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"RegistryName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
registryName,
            (Text
"SchemaName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
schemaName,
            (Text
"SchemaArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
schemaArn
          ]
      )