{-# 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.Textract.Types.ExpenseDocument
-- 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.Textract.Types.ExpenseDocument 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
import Amazonka.Textract.Types.Block
import Amazonka.Textract.Types.ExpenseField
import Amazonka.Textract.Types.LineItemGroup

-- | The structure holding all the information returned by AnalyzeExpense
--
-- /See:/ 'newExpenseDocument' smart constructor.
data ExpenseDocument = ExpenseDocument'
  { -- | This is a block object, the same as reported when DetectDocumentText is
    -- run on a document. It provides word level recognition of text.
    ExpenseDocument -> Maybe [Block]
blocks :: Prelude.Maybe [Block],
    -- | Denotes which invoice or receipt in the document the information is
    -- coming from. First document will be 1, the second 2, and so on.
    ExpenseDocument -> Maybe Natural
expenseIndex :: Prelude.Maybe Prelude.Natural,
    -- | Information detected on each table of a document, seperated into
    -- @LineItems@.
    ExpenseDocument -> Maybe [LineItemGroup]
lineItemGroups :: Prelude.Maybe [LineItemGroup],
    -- | Any information found outside of a table by Amazon Textract.
    ExpenseDocument -> Maybe [ExpenseField]
summaryFields :: Prelude.Maybe [ExpenseField]
  }
  deriving (ExpenseDocument -> ExpenseDocument -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExpenseDocument -> ExpenseDocument -> Bool
$c/= :: ExpenseDocument -> ExpenseDocument -> Bool
== :: ExpenseDocument -> ExpenseDocument -> Bool
$c== :: ExpenseDocument -> ExpenseDocument -> Bool
Prelude.Eq, ReadPrec [ExpenseDocument]
ReadPrec ExpenseDocument
Int -> ReadS ExpenseDocument
ReadS [ExpenseDocument]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExpenseDocument]
$creadListPrec :: ReadPrec [ExpenseDocument]
readPrec :: ReadPrec ExpenseDocument
$creadPrec :: ReadPrec ExpenseDocument
readList :: ReadS [ExpenseDocument]
$creadList :: ReadS [ExpenseDocument]
readsPrec :: Int -> ReadS ExpenseDocument
$creadsPrec :: Int -> ReadS ExpenseDocument
Prelude.Read, Int -> ExpenseDocument -> ShowS
[ExpenseDocument] -> ShowS
ExpenseDocument -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExpenseDocument] -> ShowS
$cshowList :: [ExpenseDocument] -> ShowS
show :: ExpenseDocument -> String
$cshow :: ExpenseDocument -> String
showsPrec :: Int -> ExpenseDocument -> ShowS
$cshowsPrec :: Int -> ExpenseDocument -> ShowS
Prelude.Show, forall x. Rep ExpenseDocument x -> ExpenseDocument
forall x. ExpenseDocument -> Rep ExpenseDocument x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ExpenseDocument x -> ExpenseDocument
$cfrom :: forall x. ExpenseDocument -> Rep ExpenseDocument x
Prelude.Generic)

-- |
-- Create a value of 'ExpenseDocument' 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:
--
-- 'blocks', 'expenseDocument_blocks' - This is a block object, the same as reported when DetectDocumentText is
-- run on a document. It provides word level recognition of text.
--
-- 'expenseIndex', 'expenseDocument_expenseIndex' - Denotes which invoice or receipt in the document the information is
-- coming from. First document will be 1, the second 2, and so on.
--
-- 'lineItemGroups', 'expenseDocument_lineItemGroups' - Information detected on each table of a document, seperated into
-- @LineItems@.
--
-- 'summaryFields', 'expenseDocument_summaryFields' - Any information found outside of a table by Amazon Textract.
newExpenseDocument ::
  ExpenseDocument
newExpenseDocument :: ExpenseDocument
newExpenseDocument =
  ExpenseDocument'
    { $sel:blocks:ExpenseDocument' :: Maybe [Block]
blocks = forall a. Maybe a
Prelude.Nothing,
      $sel:expenseIndex:ExpenseDocument' :: Maybe Natural
expenseIndex = forall a. Maybe a
Prelude.Nothing,
      $sel:lineItemGroups:ExpenseDocument' :: Maybe [LineItemGroup]
lineItemGroups = forall a. Maybe a
Prelude.Nothing,
      $sel:summaryFields:ExpenseDocument' :: Maybe [ExpenseField]
summaryFields = forall a. Maybe a
Prelude.Nothing
    }

-- | This is a block object, the same as reported when DetectDocumentText is
-- run on a document. It provides word level recognition of text.
expenseDocument_blocks :: Lens.Lens' ExpenseDocument (Prelude.Maybe [Block])
expenseDocument_blocks :: Lens' ExpenseDocument (Maybe [Block])
expenseDocument_blocks = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExpenseDocument' {Maybe [Block]
blocks :: Maybe [Block]
$sel:blocks:ExpenseDocument' :: ExpenseDocument -> Maybe [Block]
blocks} -> Maybe [Block]
blocks) (\s :: ExpenseDocument
s@ExpenseDocument' {} Maybe [Block]
a -> ExpenseDocument
s {$sel:blocks:ExpenseDocument' :: Maybe [Block]
blocks = Maybe [Block]
a} :: ExpenseDocument) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Denotes which invoice or receipt in the document the information is
-- coming from. First document will be 1, the second 2, and so on.
expenseDocument_expenseIndex :: Lens.Lens' ExpenseDocument (Prelude.Maybe Prelude.Natural)
expenseDocument_expenseIndex :: Lens' ExpenseDocument (Maybe Natural)
expenseDocument_expenseIndex = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExpenseDocument' {Maybe Natural
expenseIndex :: Maybe Natural
$sel:expenseIndex:ExpenseDocument' :: ExpenseDocument -> Maybe Natural
expenseIndex} -> Maybe Natural
expenseIndex) (\s :: ExpenseDocument
s@ExpenseDocument' {} Maybe Natural
a -> ExpenseDocument
s {$sel:expenseIndex:ExpenseDocument' :: Maybe Natural
expenseIndex = Maybe Natural
a} :: ExpenseDocument)

-- | Information detected on each table of a document, seperated into
-- @LineItems@.
expenseDocument_lineItemGroups :: Lens.Lens' ExpenseDocument (Prelude.Maybe [LineItemGroup])
expenseDocument_lineItemGroups :: Lens' ExpenseDocument (Maybe [LineItemGroup])
expenseDocument_lineItemGroups = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExpenseDocument' {Maybe [LineItemGroup]
lineItemGroups :: Maybe [LineItemGroup]
$sel:lineItemGroups:ExpenseDocument' :: ExpenseDocument -> Maybe [LineItemGroup]
lineItemGroups} -> Maybe [LineItemGroup]
lineItemGroups) (\s :: ExpenseDocument
s@ExpenseDocument' {} Maybe [LineItemGroup]
a -> ExpenseDocument
s {$sel:lineItemGroups:ExpenseDocument' :: Maybe [LineItemGroup]
lineItemGroups = Maybe [LineItemGroup]
a} :: ExpenseDocument) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Any information found outside of a table by Amazon Textract.
expenseDocument_summaryFields :: Lens.Lens' ExpenseDocument (Prelude.Maybe [ExpenseField])
expenseDocument_summaryFields :: Lens' ExpenseDocument (Maybe [ExpenseField])
expenseDocument_summaryFields = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExpenseDocument' {Maybe [ExpenseField]
summaryFields :: Maybe [ExpenseField]
$sel:summaryFields:ExpenseDocument' :: ExpenseDocument -> Maybe [ExpenseField]
summaryFields} -> Maybe [ExpenseField]
summaryFields) (\s :: ExpenseDocument
s@ExpenseDocument' {} Maybe [ExpenseField]
a -> ExpenseDocument
s {$sel:summaryFields:ExpenseDocument' :: Maybe [ExpenseField]
summaryFields = Maybe [ExpenseField]
a} :: ExpenseDocument) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON ExpenseDocument where
  parseJSON :: Value -> Parser ExpenseDocument
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ExpenseDocument"
      ( \Object
x ->
          Maybe [Block]
-> Maybe Natural
-> Maybe [LineItemGroup]
-> Maybe [ExpenseField]
-> ExpenseDocument
ExpenseDocument'
            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
"Blocks" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"ExpenseIndex")
            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
"LineItemGroups" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"SummaryFields" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ExpenseDocument where
  hashWithSalt :: Int -> ExpenseDocument -> Int
hashWithSalt Int
_salt ExpenseDocument' {Maybe Natural
Maybe [ExpenseField]
Maybe [LineItemGroup]
Maybe [Block]
summaryFields :: Maybe [ExpenseField]
lineItemGroups :: Maybe [LineItemGroup]
expenseIndex :: Maybe Natural
blocks :: Maybe [Block]
$sel:summaryFields:ExpenseDocument' :: ExpenseDocument -> Maybe [ExpenseField]
$sel:lineItemGroups:ExpenseDocument' :: ExpenseDocument -> Maybe [LineItemGroup]
$sel:expenseIndex:ExpenseDocument' :: ExpenseDocument -> Maybe Natural
$sel:blocks:ExpenseDocument' :: ExpenseDocument -> Maybe [Block]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Block]
blocks
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
expenseIndex
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [LineItemGroup]
lineItemGroups
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [ExpenseField]
summaryFields

instance Prelude.NFData ExpenseDocument where
  rnf :: ExpenseDocument -> ()
rnf ExpenseDocument' {Maybe Natural
Maybe [ExpenseField]
Maybe [LineItemGroup]
Maybe [Block]
summaryFields :: Maybe [ExpenseField]
lineItemGroups :: Maybe [LineItemGroup]
expenseIndex :: Maybe Natural
blocks :: Maybe [Block]
$sel:summaryFields:ExpenseDocument' :: ExpenseDocument -> Maybe [ExpenseField]
$sel:lineItemGroups:ExpenseDocument' :: ExpenseDocument -> Maybe [LineItemGroup]
$sel:expenseIndex:ExpenseDocument' :: ExpenseDocument -> Maybe Natural
$sel:blocks:ExpenseDocument' :: ExpenseDocument -> Maybe [Block]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Block]
blocks
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
expenseIndex
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [LineItemGroup]
lineItemGroups
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [ExpenseField]
summaryFields