{-# 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.IoTThingsGraph.Types.DefinitionDocument
-- 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.IoTThingsGraph.Types.DefinitionDocument where

import qualified Amazonka.Core as Core
import Amazonka.IoTThingsGraph.Types.DefinitionLanguage
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A document that defines an entity.
--
-- /See:/ 'newDefinitionDocument' smart constructor.
data DefinitionDocument = DefinitionDocument'
  { -- | The language used to define the entity. @GRAPHQL@ is the only valid
    -- value.
    DefinitionDocument -> DefinitionLanguage
language :: DefinitionLanguage,
    -- | The GraphQL text that defines the entity.
    DefinitionDocument -> Text
text :: Prelude.Text
  }
  deriving (DefinitionDocument -> DefinitionDocument -> Bool
(DefinitionDocument -> DefinitionDocument -> Bool)
-> (DefinitionDocument -> DefinitionDocument -> Bool)
-> Eq DefinitionDocument
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DefinitionDocument -> DefinitionDocument -> Bool
$c/= :: DefinitionDocument -> DefinitionDocument -> Bool
== :: DefinitionDocument -> DefinitionDocument -> Bool
$c== :: DefinitionDocument -> DefinitionDocument -> Bool
Prelude.Eq, ReadPrec [DefinitionDocument]
ReadPrec DefinitionDocument
Int -> ReadS DefinitionDocument
ReadS [DefinitionDocument]
(Int -> ReadS DefinitionDocument)
-> ReadS [DefinitionDocument]
-> ReadPrec DefinitionDocument
-> ReadPrec [DefinitionDocument]
-> Read DefinitionDocument
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DefinitionDocument]
$creadListPrec :: ReadPrec [DefinitionDocument]
readPrec :: ReadPrec DefinitionDocument
$creadPrec :: ReadPrec DefinitionDocument
readList :: ReadS [DefinitionDocument]
$creadList :: ReadS [DefinitionDocument]
readsPrec :: Int -> ReadS DefinitionDocument
$creadsPrec :: Int -> ReadS DefinitionDocument
Prelude.Read, Int -> DefinitionDocument -> ShowS
[DefinitionDocument] -> ShowS
DefinitionDocument -> String
(Int -> DefinitionDocument -> ShowS)
-> (DefinitionDocument -> String)
-> ([DefinitionDocument] -> ShowS)
-> Show DefinitionDocument
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DefinitionDocument] -> ShowS
$cshowList :: [DefinitionDocument] -> ShowS
show :: DefinitionDocument -> String
$cshow :: DefinitionDocument -> String
showsPrec :: Int -> DefinitionDocument -> ShowS
$cshowsPrec :: Int -> DefinitionDocument -> ShowS
Prelude.Show, (forall x. DefinitionDocument -> Rep DefinitionDocument x)
-> (forall x. Rep DefinitionDocument x -> DefinitionDocument)
-> Generic DefinitionDocument
forall x. Rep DefinitionDocument x -> DefinitionDocument
forall x. DefinitionDocument -> Rep DefinitionDocument x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DefinitionDocument x -> DefinitionDocument
$cfrom :: forall x. DefinitionDocument -> Rep DefinitionDocument x
Prelude.Generic)

-- |
-- Create a value of 'DefinitionDocument' 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:
--
-- 'language', 'definitionDocument_language' - The language used to define the entity. @GRAPHQL@ is the only valid
-- value.
--
-- 'text', 'definitionDocument_text' - The GraphQL text that defines the entity.
newDefinitionDocument ::
  -- | 'language'
  DefinitionLanguage ->
  -- | 'text'
  Prelude.Text ->
  DefinitionDocument
newDefinitionDocument :: DefinitionLanguage -> Text -> DefinitionDocument
newDefinitionDocument DefinitionLanguage
pLanguage_ Text
pText_ =
  DefinitionDocument' :: DefinitionLanguage -> Text -> DefinitionDocument
DefinitionDocument'
    { $sel:language:DefinitionDocument' :: DefinitionLanguage
language = DefinitionLanguage
pLanguage_,
      $sel:text:DefinitionDocument' :: Text
text = Text
pText_
    }

-- | The language used to define the entity. @GRAPHQL@ is the only valid
-- value.
definitionDocument_language :: Lens.Lens' DefinitionDocument DefinitionLanguage
definitionDocument_language :: (DefinitionLanguage -> f DefinitionLanguage)
-> DefinitionDocument -> f DefinitionDocument
definitionDocument_language = (DefinitionDocument -> DefinitionLanguage)
-> (DefinitionDocument -> DefinitionLanguage -> DefinitionDocument)
-> Lens
     DefinitionDocument
     DefinitionDocument
     DefinitionLanguage
     DefinitionLanguage
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DefinitionDocument' {DefinitionLanguage
language :: DefinitionLanguage
$sel:language:DefinitionDocument' :: DefinitionDocument -> DefinitionLanguage
language} -> DefinitionLanguage
language) (\s :: DefinitionDocument
s@DefinitionDocument' {} DefinitionLanguage
a -> DefinitionDocument
s {$sel:language:DefinitionDocument' :: DefinitionLanguage
language = DefinitionLanguage
a} :: DefinitionDocument)

-- | The GraphQL text that defines the entity.
definitionDocument_text :: Lens.Lens' DefinitionDocument Prelude.Text
definitionDocument_text :: (Text -> f Text) -> DefinitionDocument -> f DefinitionDocument
definitionDocument_text = (DefinitionDocument -> Text)
-> (DefinitionDocument -> Text -> DefinitionDocument)
-> Lens DefinitionDocument DefinitionDocument Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DefinitionDocument' {Text
text :: Text
$sel:text:DefinitionDocument' :: DefinitionDocument -> Text
text} -> Text
text) (\s :: DefinitionDocument
s@DefinitionDocument' {} Text
a -> DefinitionDocument
s {$sel:text:DefinitionDocument' :: Text
text = Text
a} :: DefinitionDocument)

instance Core.FromJSON DefinitionDocument where
  parseJSON :: Value -> Parser DefinitionDocument
parseJSON =
    String
-> (Object -> Parser DefinitionDocument)
-> Value
-> Parser DefinitionDocument
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DefinitionDocument"
      ( \Object
x ->
          DefinitionLanguage -> Text -> DefinitionDocument
DefinitionDocument'
            (DefinitionLanguage -> Text -> DefinitionDocument)
-> Parser DefinitionLanguage -> Parser (Text -> DefinitionDocument)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser DefinitionLanguage
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"language")
            Parser (Text -> DefinitionDocument)
-> Parser Text -> Parser DefinitionDocument
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"text")
      )

instance Prelude.Hashable DefinitionDocument

instance Prelude.NFData DefinitionDocument

instance Core.ToJSON DefinitionDocument where
  toJSON :: DefinitionDocument -> Value
toJSON DefinitionDocument' {Text
DefinitionLanguage
text :: Text
language :: DefinitionLanguage
$sel:text:DefinitionDocument' :: DefinitionDocument -> Text
$sel:language:DefinitionDocument' :: DefinitionDocument -> DefinitionLanguage
..} =
    [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
"language" Text -> DefinitionLanguage -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= DefinitionLanguage
language),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"text" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
text)
          ]
      )