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

import qualified Amazonka.Core as Core
import Amazonka.Glue.Types.SchemaId
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that references a schema stored in the Glue Schema Registry.
--
-- /See:/ 'newSchemaReference' smart constructor.
data SchemaReference = SchemaReference'
  { -- | The unique ID assigned to a version of the schema. Either this or the
    -- @SchemaId@ has to be provided.
    SchemaReference -> Maybe Text
schemaVersionId :: Prelude.Maybe Prelude.Text,
    -- | A structure that contains schema identity fields. Either this or the
    -- @SchemaVersionId@ has to be provided.
    SchemaReference -> Maybe SchemaId
schemaId :: Prelude.Maybe SchemaId,
    -- | The version number of the schema.
    SchemaReference -> Maybe Natural
schemaVersionNumber :: Prelude.Maybe Prelude.Natural
  }
  deriving (SchemaReference -> SchemaReference -> Bool
(SchemaReference -> SchemaReference -> Bool)
-> (SchemaReference -> SchemaReference -> Bool)
-> Eq SchemaReference
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SchemaReference -> SchemaReference -> Bool
$c/= :: SchemaReference -> SchemaReference -> Bool
== :: SchemaReference -> SchemaReference -> Bool
$c== :: SchemaReference -> SchemaReference -> Bool
Prelude.Eq, ReadPrec [SchemaReference]
ReadPrec SchemaReference
Int -> ReadS SchemaReference
ReadS [SchemaReference]
(Int -> ReadS SchemaReference)
-> ReadS [SchemaReference]
-> ReadPrec SchemaReference
-> ReadPrec [SchemaReference]
-> Read SchemaReference
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SchemaReference]
$creadListPrec :: ReadPrec [SchemaReference]
readPrec :: ReadPrec SchemaReference
$creadPrec :: ReadPrec SchemaReference
readList :: ReadS [SchemaReference]
$creadList :: ReadS [SchemaReference]
readsPrec :: Int -> ReadS SchemaReference
$creadsPrec :: Int -> ReadS SchemaReference
Prelude.Read, Int -> SchemaReference -> ShowS
[SchemaReference] -> ShowS
SchemaReference -> String
(Int -> SchemaReference -> ShowS)
-> (SchemaReference -> String)
-> ([SchemaReference] -> ShowS)
-> Show SchemaReference
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SchemaReference] -> ShowS
$cshowList :: [SchemaReference] -> ShowS
show :: SchemaReference -> String
$cshow :: SchemaReference -> String
showsPrec :: Int -> SchemaReference -> ShowS
$cshowsPrec :: Int -> SchemaReference -> ShowS
Prelude.Show, (forall x. SchemaReference -> Rep SchemaReference x)
-> (forall x. Rep SchemaReference x -> SchemaReference)
-> Generic SchemaReference
forall x. Rep SchemaReference x -> SchemaReference
forall x. SchemaReference -> Rep SchemaReference x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SchemaReference x -> SchemaReference
$cfrom :: forall x. SchemaReference -> Rep SchemaReference x
Prelude.Generic)

-- |
-- Create a value of 'SchemaReference' 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:
--
-- 'schemaVersionId', 'schemaReference_schemaVersionId' - The unique ID assigned to a version of the schema. Either this or the
-- @SchemaId@ has to be provided.
--
-- 'schemaId', 'schemaReference_schemaId' - A structure that contains schema identity fields. Either this or the
-- @SchemaVersionId@ has to be provided.
--
-- 'schemaVersionNumber', 'schemaReference_schemaVersionNumber' - The version number of the schema.
newSchemaReference ::
  SchemaReference
newSchemaReference :: SchemaReference
newSchemaReference =
  SchemaReference' :: Maybe Text -> Maybe SchemaId -> Maybe Natural -> SchemaReference
SchemaReference'
    { $sel:schemaVersionId:SchemaReference' :: Maybe Text
schemaVersionId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:schemaId:SchemaReference' :: Maybe SchemaId
schemaId = Maybe SchemaId
forall a. Maybe a
Prelude.Nothing,
      $sel:schemaVersionNumber:SchemaReference' :: Maybe Natural
schemaVersionNumber = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The unique ID assigned to a version of the schema. Either this or the
-- @SchemaId@ has to be provided.
schemaReference_schemaVersionId :: Lens.Lens' SchemaReference (Prelude.Maybe Prelude.Text)
schemaReference_schemaVersionId :: (Maybe Text -> f (Maybe Text))
-> SchemaReference -> f SchemaReference
schemaReference_schemaVersionId = (SchemaReference -> Maybe Text)
-> (SchemaReference -> Maybe Text -> SchemaReference)
-> Lens SchemaReference SchemaReference (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SchemaReference' {Maybe Text
schemaVersionId :: Maybe Text
$sel:schemaVersionId:SchemaReference' :: SchemaReference -> Maybe Text
schemaVersionId} -> Maybe Text
schemaVersionId) (\s :: SchemaReference
s@SchemaReference' {} Maybe Text
a -> SchemaReference
s {$sel:schemaVersionId:SchemaReference' :: Maybe Text
schemaVersionId = Maybe Text
a} :: SchemaReference)

-- | A structure that contains schema identity fields. Either this or the
-- @SchemaVersionId@ has to be provided.
schemaReference_schemaId :: Lens.Lens' SchemaReference (Prelude.Maybe SchemaId)
schemaReference_schemaId :: (Maybe SchemaId -> f (Maybe SchemaId))
-> SchemaReference -> f SchemaReference
schemaReference_schemaId = (SchemaReference -> Maybe SchemaId)
-> (SchemaReference -> Maybe SchemaId -> SchemaReference)
-> Lens
     SchemaReference SchemaReference (Maybe SchemaId) (Maybe SchemaId)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SchemaReference' {Maybe SchemaId
schemaId :: Maybe SchemaId
$sel:schemaId:SchemaReference' :: SchemaReference -> Maybe SchemaId
schemaId} -> Maybe SchemaId
schemaId) (\s :: SchemaReference
s@SchemaReference' {} Maybe SchemaId
a -> SchemaReference
s {$sel:schemaId:SchemaReference' :: Maybe SchemaId
schemaId = Maybe SchemaId
a} :: SchemaReference)

-- | The version number of the schema.
schemaReference_schemaVersionNumber :: Lens.Lens' SchemaReference (Prelude.Maybe Prelude.Natural)
schemaReference_schemaVersionNumber :: (Maybe Natural -> f (Maybe Natural))
-> SchemaReference -> f SchemaReference
schemaReference_schemaVersionNumber = (SchemaReference -> Maybe Natural)
-> (SchemaReference -> Maybe Natural -> SchemaReference)
-> Lens
     SchemaReference SchemaReference (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SchemaReference' {Maybe Natural
schemaVersionNumber :: Maybe Natural
$sel:schemaVersionNumber:SchemaReference' :: SchemaReference -> Maybe Natural
schemaVersionNumber} -> Maybe Natural
schemaVersionNumber) (\s :: SchemaReference
s@SchemaReference' {} Maybe Natural
a -> SchemaReference
s {$sel:schemaVersionNumber:SchemaReference' :: Maybe Natural
schemaVersionNumber = Maybe Natural
a} :: SchemaReference)

instance Core.FromJSON SchemaReference where
  parseJSON :: Value -> Parser SchemaReference
parseJSON =
    String
-> (Object -> Parser SchemaReference)
-> Value
-> Parser SchemaReference
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SchemaReference"
      ( \Object
x ->
          Maybe Text -> Maybe SchemaId -> Maybe Natural -> SchemaReference
SchemaReference'
            (Maybe Text -> Maybe SchemaId -> Maybe Natural -> SchemaReference)
-> Parser (Maybe Text)
-> Parser (Maybe SchemaId -> Maybe Natural -> SchemaReference)
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
"SchemaVersionId")
            Parser (Maybe SchemaId -> Maybe Natural -> SchemaReference)
-> Parser (Maybe SchemaId)
-> Parser (Maybe Natural -> SchemaReference)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SchemaId)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SchemaId")
            Parser (Maybe Natural -> SchemaReference)
-> Parser (Maybe Natural) -> Parser SchemaReference
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SchemaVersionNumber")
      )

instance Prelude.Hashable SchemaReference

instance Prelude.NFData SchemaReference

instance Core.ToJSON SchemaReference where
  toJSON :: SchemaReference -> Value
toJSON SchemaReference' {Maybe Natural
Maybe Text
Maybe SchemaId
schemaVersionNumber :: Maybe Natural
schemaId :: Maybe SchemaId
schemaVersionId :: Maybe Text
$sel:schemaVersionNumber:SchemaReference' :: SchemaReference -> Maybe Natural
$sel:schemaId:SchemaReference' :: SchemaReference -> Maybe SchemaId
$sel:schemaVersionId:SchemaReference' :: SchemaReference -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"SchemaVersionId" 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
schemaVersionId,
            (Text
"SchemaId" Text -> SchemaId -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SchemaId -> Pair) -> Maybe SchemaId -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SchemaId
schemaId,
            (Text
"SchemaVersionNumber" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
schemaVersionNumber
          ]
      )