{-# 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.Relationship
-- 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.Textract.Types.Relationship where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Textract.Types.RelationshipType

-- | Information about how blocks are related to each other. A @Block@ object
-- contains 0 or more @Relation@ objects in a list, @Relationships@. For
-- more information, see Block.
--
-- The @Type@ element provides the type of the relationship for all blocks
-- in the @IDs@ array.
--
-- /See:/ 'newRelationship' smart constructor.
data Relationship = Relationship'
  { -- | An array of IDs for related blocks. You can get the type of the
    -- relationship from the @Type@ element.
    Relationship -> Maybe [Text]
ids :: Prelude.Maybe [Prelude.Text],
    -- | The type of relationship that the blocks in the IDs array have with the
    -- current block. The relationship can be @VALUE@ or @CHILD@. A
    -- relationship of type VALUE is a list that contains the ID of the VALUE
    -- block that\'s associated with the KEY of a key-value pair. A
    -- relationship of type CHILD is a list of IDs that identify WORD blocks in
    -- the case of lines Cell blocks in the case of Tables, and WORD blocks in
    -- the case of Selection Elements.
    Relationship -> Maybe RelationshipType
type' :: Prelude.Maybe RelationshipType
  }
  deriving (Relationship -> Relationship -> Bool
(Relationship -> Relationship -> Bool)
-> (Relationship -> Relationship -> Bool) -> Eq Relationship
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Relationship -> Relationship -> Bool
$c/= :: Relationship -> Relationship -> Bool
== :: Relationship -> Relationship -> Bool
$c== :: Relationship -> Relationship -> Bool
Prelude.Eq, ReadPrec [Relationship]
ReadPrec Relationship
Int -> ReadS Relationship
ReadS [Relationship]
(Int -> ReadS Relationship)
-> ReadS [Relationship]
-> ReadPrec Relationship
-> ReadPrec [Relationship]
-> Read Relationship
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Relationship]
$creadListPrec :: ReadPrec [Relationship]
readPrec :: ReadPrec Relationship
$creadPrec :: ReadPrec Relationship
readList :: ReadS [Relationship]
$creadList :: ReadS [Relationship]
readsPrec :: Int -> ReadS Relationship
$creadsPrec :: Int -> ReadS Relationship
Prelude.Read, Int -> Relationship -> ShowS
[Relationship] -> ShowS
Relationship -> String
(Int -> Relationship -> ShowS)
-> (Relationship -> String)
-> ([Relationship] -> ShowS)
-> Show Relationship
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Relationship] -> ShowS
$cshowList :: [Relationship] -> ShowS
show :: Relationship -> String
$cshow :: Relationship -> String
showsPrec :: Int -> Relationship -> ShowS
$cshowsPrec :: Int -> Relationship -> ShowS
Prelude.Show, (forall x. Relationship -> Rep Relationship x)
-> (forall x. Rep Relationship x -> Relationship)
-> Generic Relationship
forall x. Rep Relationship x -> Relationship
forall x. Relationship -> Rep Relationship x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Relationship x -> Relationship
$cfrom :: forall x. Relationship -> Rep Relationship x
Prelude.Generic)

-- |
-- Create a value of 'Relationship' 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:
--
-- 'ids', 'relationship_ids' - An array of IDs for related blocks. You can get the type of the
-- relationship from the @Type@ element.
--
-- 'type'', 'relationship_type' - The type of relationship that the blocks in the IDs array have with the
-- current block. The relationship can be @VALUE@ or @CHILD@. A
-- relationship of type VALUE is a list that contains the ID of the VALUE
-- block that\'s associated with the KEY of a key-value pair. A
-- relationship of type CHILD is a list of IDs that identify WORD blocks in
-- the case of lines Cell blocks in the case of Tables, and WORD blocks in
-- the case of Selection Elements.
newRelationship ::
  Relationship
newRelationship :: Relationship
newRelationship =
  Relationship' :: Maybe [Text] -> Maybe RelationshipType -> Relationship
Relationship'
    { $sel:ids:Relationship' :: Maybe [Text]
ids = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:type':Relationship' :: Maybe RelationshipType
type' = Maybe RelationshipType
forall a. Maybe a
Prelude.Nothing
    }

-- | An array of IDs for related blocks. You can get the type of the
-- relationship from the @Type@ element.
relationship_ids :: Lens.Lens' Relationship (Prelude.Maybe [Prelude.Text])
relationship_ids :: (Maybe [Text] -> f (Maybe [Text]))
-> Relationship -> f Relationship
relationship_ids = (Relationship -> Maybe [Text])
-> (Relationship -> Maybe [Text] -> Relationship)
-> Lens Relationship Relationship (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Relationship' {Maybe [Text]
ids :: Maybe [Text]
$sel:ids:Relationship' :: Relationship -> Maybe [Text]
ids} -> Maybe [Text]
ids) (\s :: Relationship
s@Relationship' {} Maybe [Text]
a -> Relationship
s {$sel:ids:Relationship' :: Maybe [Text]
ids = Maybe [Text]
a} :: Relationship) ((Maybe [Text] -> f (Maybe [Text]))
 -> Relationship -> f Relationship)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> Relationship
-> f Relationship
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The type of relationship that the blocks in the IDs array have with the
-- current block. The relationship can be @VALUE@ or @CHILD@. A
-- relationship of type VALUE is a list that contains the ID of the VALUE
-- block that\'s associated with the KEY of a key-value pair. A
-- relationship of type CHILD is a list of IDs that identify WORD blocks in
-- the case of lines Cell blocks in the case of Tables, and WORD blocks in
-- the case of Selection Elements.
relationship_type :: Lens.Lens' Relationship (Prelude.Maybe RelationshipType)
relationship_type :: (Maybe RelationshipType -> f (Maybe RelationshipType))
-> Relationship -> f Relationship
relationship_type = (Relationship -> Maybe RelationshipType)
-> (Relationship -> Maybe RelationshipType -> Relationship)
-> Lens
     Relationship
     Relationship
     (Maybe RelationshipType)
     (Maybe RelationshipType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Relationship' {Maybe RelationshipType
type' :: Maybe RelationshipType
$sel:type':Relationship' :: Relationship -> Maybe RelationshipType
type'} -> Maybe RelationshipType
type') (\s :: Relationship
s@Relationship' {} Maybe RelationshipType
a -> Relationship
s {$sel:type':Relationship' :: Maybe RelationshipType
type' = Maybe RelationshipType
a} :: Relationship)

instance Core.FromJSON Relationship where
  parseJSON :: Value -> Parser Relationship
parseJSON =
    String
-> (Object -> Parser Relationship) -> Value -> Parser Relationship
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Relationship"
      ( \Object
x ->
          Maybe [Text] -> Maybe RelationshipType -> Relationship
Relationship'
            (Maybe [Text] -> Maybe RelationshipType -> Relationship)
-> Parser (Maybe [Text])
-> Parser (Maybe RelationshipType -> Relationship)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Ids" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe RelationshipType -> Relationship)
-> Parser (Maybe RelationshipType) -> Parser Relationship
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe RelationshipType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Type")
      )

instance Prelude.Hashable Relationship

instance Prelude.NFData Relationship