{-# 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.Wisdom.Types.Document
-- 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.Wisdom.Types.Document where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Wisdom.Types.ContentReference
import Amazonka.Wisdom.Types.DocumentText

-- | The document.
--
-- /See:/ 'newDocument' smart constructor.
data Document = Document'
  { -- | The excerpt from the document.
    Document -> Maybe DocumentText
excerpt :: Prelude.Maybe DocumentText,
    -- | The title of the document.
    Document -> Maybe DocumentText
title :: Prelude.Maybe DocumentText,
    -- | A reference to the content resource.
    Document -> ContentReference
contentReference :: ContentReference
  }
  deriving (Document -> Document -> Bool
(Document -> Document -> Bool)
-> (Document -> Document -> Bool) -> Eq Document
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Document -> Document -> Bool
$c/= :: Document -> Document -> Bool
== :: Document -> Document -> Bool
$c== :: Document -> Document -> Bool
Prelude.Eq, Int -> Document -> ShowS
[Document] -> ShowS
Document -> String
(Int -> Document -> ShowS)
-> (Document -> String) -> ([Document] -> ShowS) -> Show Document
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Document] -> ShowS
$cshowList :: [Document] -> ShowS
show :: Document -> String
$cshow :: Document -> String
showsPrec :: Int -> Document -> ShowS
$cshowsPrec :: Int -> Document -> ShowS
Prelude.Show, (forall x. Document -> Rep Document x)
-> (forall x. Rep Document x -> Document) -> Generic Document
forall x. Rep Document x -> Document
forall x. Document -> Rep Document x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Document x -> Document
$cfrom :: forall x. Document -> Rep Document x
Prelude.Generic)

-- |
-- Create a value of 'Document' 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:
--
-- 'excerpt', 'document_excerpt' - The excerpt from the document.
--
-- 'title', 'document_title' - The title of the document.
--
-- 'contentReference', 'document_contentReference' - A reference to the content resource.
newDocument ::
  -- | 'contentReference'
  ContentReference ->
  Document
newDocument :: ContentReference -> Document
newDocument ContentReference
pContentReference_ =
  Document' :: Maybe DocumentText
-> Maybe DocumentText -> ContentReference -> Document
Document'
    { $sel:excerpt:Document' :: Maybe DocumentText
excerpt = Maybe DocumentText
forall a. Maybe a
Prelude.Nothing,
      $sel:title:Document' :: Maybe DocumentText
title = Maybe DocumentText
forall a. Maybe a
Prelude.Nothing,
      $sel:contentReference:Document' :: ContentReference
contentReference = ContentReference
pContentReference_
    }

-- | The excerpt from the document.
document_excerpt :: Lens.Lens' Document (Prelude.Maybe DocumentText)
document_excerpt :: (Maybe DocumentText -> f (Maybe DocumentText))
-> Document -> f Document
document_excerpt = (Document -> Maybe DocumentText)
-> (Document -> Maybe DocumentText -> Document)
-> Lens Document Document (Maybe DocumentText) (Maybe DocumentText)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Document' {Maybe DocumentText
excerpt :: Maybe DocumentText
$sel:excerpt:Document' :: Document -> Maybe DocumentText
excerpt} -> Maybe DocumentText
excerpt) (\s :: Document
s@Document' {} Maybe DocumentText
a -> Document
s {$sel:excerpt:Document' :: Maybe DocumentText
excerpt = Maybe DocumentText
a} :: Document)

-- | The title of the document.
document_title :: Lens.Lens' Document (Prelude.Maybe DocumentText)
document_title :: (Maybe DocumentText -> f (Maybe DocumentText))
-> Document -> f Document
document_title = (Document -> Maybe DocumentText)
-> (Document -> Maybe DocumentText -> Document)
-> Lens Document Document (Maybe DocumentText) (Maybe DocumentText)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Document' {Maybe DocumentText
title :: Maybe DocumentText
$sel:title:Document' :: Document -> Maybe DocumentText
title} -> Maybe DocumentText
title) (\s :: Document
s@Document' {} Maybe DocumentText
a -> Document
s {$sel:title:Document' :: Maybe DocumentText
title = Maybe DocumentText
a} :: Document)

-- | A reference to the content resource.
document_contentReference :: Lens.Lens' Document ContentReference
document_contentReference :: (ContentReference -> f ContentReference) -> Document -> f Document
document_contentReference = (Document -> ContentReference)
-> (Document -> ContentReference -> Document)
-> Lens Document Document ContentReference ContentReference
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Document' {ContentReference
contentReference :: ContentReference
$sel:contentReference:Document' :: Document -> ContentReference
contentReference} -> ContentReference
contentReference) (\s :: Document
s@Document' {} ContentReference
a -> Document
s {$sel:contentReference:Document' :: ContentReference
contentReference = ContentReference
a} :: Document)

instance Core.FromJSON Document where
  parseJSON :: Value -> Parser Document
parseJSON =
    String -> (Object -> Parser Document) -> Value -> Parser Document
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Document"
      ( \Object
x ->
          Maybe DocumentText
-> Maybe DocumentText -> ContentReference -> Document
Document'
            (Maybe DocumentText
 -> Maybe DocumentText -> ContentReference -> Document)
-> Parser (Maybe DocumentText)
-> Parser (Maybe DocumentText -> ContentReference -> Document)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe DocumentText)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"excerpt")
            Parser (Maybe DocumentText -> ContentReference -> Document)
-> Parser (Maybe DocumentText)
-> Parser (ContentReference -> Document)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe DocumentText)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"title")
            Parser (ContentReference -> Document)
-> Parser ContentReference -> Parser Document
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ContentReference
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"contentReference")
      )

instance Prelude.Hashable Document

instance Prelude.NFData Document