{-# 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.Query
-- 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.Query 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

-- | Each query contains the question you want to ask in the Text and the
-- alias you want to associate.
--
-- /See:/ 'newQuery' smart constructor.
data Query = Query'
  { -- | Alias attached to the query, for ease of location.
    Query -> Maybe Text
alias :: Prelude.Maybe Prelude.Text,
    -- | Pages is a parameter that the user inputs to specify which pages to
    -- apply a query to. The following is a list of rules for using this
    -- parameter.
    --
    -- -   If a page is not specified, it is set to @[\"1\"]@ by default.
    --
    -- -   The following characters are allowed in the parameter\'s string:
    --     @0 1 2 3 4 5 6 7 8 9 - *@. No whitespace is allowed.
    --
    -- -   When using * to indicate all pages, it must be the only element in
    --     the list.
    --
    -- -   You can use page intervals, such as @[“1-3”, “1-1”, “4-*”]@. Where
    --     @*@ indicates last page of document.
    --
    -- -   Specified pages must be greater than 0 and less than or equal to the
    --     number of pages in the document.
    Query -> Maybe (NonEmpty Text)
pages :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | Question that Amazon Textract will apply to the document. An example
    -- would be \"What is the customer\'s SSN?\"
    Query -> Text
text :: Prelude.Text
  }
  deriving (Query -> Query -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Query -> Query -> Bool
$c/= :: Query -> Query -> Bool
== :: Query -> Query -> Bool
$c== :: Query -> Query -> Bool
Prelude.Eq, ReadPrec [Query]
ReadPrec Query
Int -> ReadS Query
ReadS [Query]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Query]
$creadListPrec :: ReadPrec [Query]
readPrec :: ReadPrec Query
$creadPrec :: ReadPrec Query
readList :: ReadS [Query]
$creadList :: ReadS [Query]
readsPrec :: Int -> ReadS Query
$creadsPrec :: Int -> ReadS Query
Prelude.Read, Int -> Query -> ShowS
[Query] -> ShowS
Query -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Query] -> ShowS
$cshowList :: [Query] -> ShowS
show :: Query -> String
$cshow :: Query -> String
showsPrec :: Int -> Query -> ShowS
$cshowsPrec :: Int -> Query -> ShowS
Prelude.Show, forall x. Rep Query x -> Query
forall x. Query -> Rep Query x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Query x -> Query
$cfrom :: forall x. Query -> Rep Query x
Prelude.Generic)

-- |
-- Create a value of 'Query' 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:
--
-- 'alias', 'query_alias' - Alias attached to the query, for ease of location.
--
-- 'pages', 'query_pages' - Pages is a parameter that the user inputs to specify which pages to
-- apply a query to. The following is a list of rules for using this
-- parameter.
--
-- -   If a page is not specified, it is set to @[\"1\"]@ by default.
--
-- -   The following characters are allowed in the parameter\'s string:
--     @0 1 2 3 4 5 6 7 8 9 - *@. No whitespace is allowed.
--
-- -   When using * to indicate all pages, it must be the only element in
--     the list.
--
-- -   You can use page intervals, such as @[“1-3”, “1-1”, “4-*”]@. Where
--     @*@ indicates last page of document.
--
-- -   Specified pages must be greater than 0 and less than or equal to the
--     number of pages in the document.
--
-- 'text', 'query_text' - Question that Amazon Textract will apply to the document. An example
-- would be \"What is the customer\'s SSN?\"
newQuery ::
  -- | 'text'
  Prelude.Text ->
  Query
newQuery :: Text -> Query
newQuery Text
pText_ =
  Query'
    { $sel:alias:Query' :: Maybe Text
alias = forall a. Maybe a
Prelude.Nothing,
      $sel:pages:Query' :: Maybe (NonEmpty Text)
pages = forall a. Maybe a
Prelude.Nothing,
      $sel:text:Query' :: Text
text = Text
pText_
    }

-- | Alias attached to the query, for ease of location.
query_alias :: Lens.Lens' Query (Prelude.Maybe Prelude.Text)
query_alias :: Lens' Query (Maybe Text)
query_alias = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Query' {Maybe Text
alias :: Maybe Text
$sel:alias:Query' :: Query -> Maybe Text
alias} -> Maybe Text
alias) (\s :: Query
s@Query' {} Maybe Text
a -> Query
s {$sel:alias:Query' :: Maybe Text
alias = Maybe Text
a} :: Query)

-- | Pages is a parameter that the user inputs to specify which pages to
-- apply a query to. The following is a list of rules for using this
-- parameter.
--
-- -   If a page is not specified, it is set to @[\"1\"]@ by default.
--
-- -   The following characters are allowed in the parameter\'s string:
--     @0 1 2 3 4 5 6 7 8 9 - *@. No whitespace is allowed.
--
-- -   When using * to indicate all pages, it must be the only element in
--     the list.
--
-- -   You can use page intervals, such as @[“1-3”, “1-1”, “4-*”]@. Where
--     @*@ indicates last page of document.
--
-- -   Specified pages must be greater than 0 and less than or equal to the
--     number of pages in the document.
query_pages :: Lens.Lens' Query (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
query_pages :: Lens' Query (Maybe (NonEmpty Text))
query_pages = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Query' {Maybe (NonEmpty Text)
pages :: Maybe (NonEmpty Text)
$sel:pages:Query' :: Query -> Maybe (NonEmpty Text)
pages} -> Maybe (NonEmpty Text)
pages) (\s :: Query
s@Query' {} Maybe (NonEmpty Text)
a -> Query
s {$sel:pages:Query' :: Maybe (NonEmpty Text)
pages = Maybe (NonEmpty Text)
a} :: Query) 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

-- | Question that Amazon Textract will apply to the document. An example
-- would be \"What is the customer\'s SSN?\"
query_text :: Lens.Lens' Query Prelude.Text
query_text :: Lens' Query Text
query_text = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Query' {Text
text :: Text
$sel:text:Query' :: Query -> Text
text} -> Text
text) (\s :: Query
s@Query' {} Text
a -> Query
s {$sel:text:Query' :: Text
text = Text
a} :: Query)

instance Data.FromJSON Query where
  parseJSON :: Value -> Parser Query
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Query"
      ( \Object
x ->
          Maybe Text -> Maybe (NonEmpty Text) -> Text -> Query
Query'
            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
"Alias")
            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
"Pages")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Text")
      )

instance Prelude.Hashable Query where
  hashWithSalt :: Int -> Query -> Int
hashWithSalt Int
_salt Query' {Maybe (NonEmpty Text)
Maybe Text
Text
text :: Text
pages :: Maybe (NonEmpty Text)
alias :: Maybe Text
$sel:text:Query' :: Query -> Text
$sel:pages:Query' :: Query -> Maybe (NonEmpty Text)
$sel:alias:Query' :: Query -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
alias
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
pages
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
text

instance Prelude.NFData Query where
  rnf :: Query -> ()
rnf Query' {Maybe (NonEmpty Text)
Maybe Text
Text
text :: Text
pages :: Maybe (NonEmpty Text)
alias :: Maybe Text
$sel:text:Query' :: Query -> Text
$sel:pages:Query' :: Query -> Maybe (NonEmpty Text)
$sel:alias:Query' :: Query -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
alias
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
pages
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
text

instance Data.ToJSON Query where
  toJSON :: Query -> Value
toJSON Query' {Maybe (NonEmpty Text)
Maybe Text
Text
text :: Text
pages :: Maybe (NonEmpty Text)
alias :: Maybe Text
$sel:text:Query' :: Query -> Text
$sel:pages:Query' :: Query -> Maybe (NonEmpty Text)
$sel:alias:Query' :: Query -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Alias" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
alias,
            (Key
"Pages" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
pages,
            forall a. a -> Maybe a
Prelude.Just (Key
"Text" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
text)
          ]
      )