{-# 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.QuickSight.Types.JoinInstruction
-- 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.QuickSight.Types.JoinInstruction 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.QuickSight.Types.JoinKeyProperties
import Amazonka.QuickSight.Types.JoinType

-- | The instructions associated with a join.
--
-- /See:/ 'newJoinInstruction' smart constructor.
data JoinInstruction = JoinInstruction'
  { -- | Join key properties of the left operand.
    JoinInstruction -> Maybe JoinKeyProperties
leftJoinKeyProperties :: Prelude.Maybe JoinKeyProperties,
    -- | Join key properties of the right operand.
    JoinInstruction -> Maybe JoinKeyProperties
rightJoinKeyProperties :: Prelude.Maybe JoinKeyProperties,
    -- | The operand on the left side of a join.
    JoinInstruction -> Text
leftOperand :: Prelude.Text,
    -- | The operand on the right side of a join.
    JoinInstruction -> Text
rightOperand :: Prelude.Text,
    -- | The type of join that it is.
    JoinInstruction -> JoinType
type' :: JoinType,
    -- | The join instructions provided in the @ON@ clause of a join.
    JoinInstruction -> Text
onClause :: Prelude.Text
  }
  deriving (JoinInstruction -> JoinInstruction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JoinInstruction -> JoinInstruction -> Bool
$c/= :: JoinInstruction -> JoinInstruction -> Bool
== :: JoinInstruction -> JoinInstruction -> Bool
$c== :: JoinInstruction -> JoinInstruction -> Bool
Prelude.Eq, ReadPrec [JoinInstruction]
ReadPrec JoinInstruction
Int -> ReadS JoinInstruction
ReadS [JoinInstruction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [JoinInstruction]
$creadListPrec :: ReadPrec [JoinInstruction]
readPrec :: ReadPrec JoinInstruction
$creadPrec :: ReadPrec JoinInstruction
readList :: ReadS [JoinInstruction]
$creadList :: ReadS [JoinInstruction]
readsPrec :: Int -> ReadS JoinInstruction
$creadsPrec :: Int -> ReadS JoinInstruction
Prelude.Read, Int -> JoinInstruction -> ShowS
[JoinInstruction] -> ShowS
JoinInstruction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JoinInstruction] -> ShowS
$cshowList :: [JoinInstruction] -> ShowS
show :: JoinInstruction -> String
$cshow :: JoinInstruction -> String
showsPrec :: Int -> JoinInstruction -> ShowS
$cshowsPrec :: Int -> JoinInstruction -> ShowS
Prelude.Show, forall x. Rep JoinInstruction x -> JoinInstruction
forall x. JoinInstruction -> Rep JoinInstruction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep JoinInstruction x -> JoinInstruction
$cfrom :: forall x. JoinInstruction -> Rep JoinInstruction x
Prelude.Generic)

-- |
-- Create a value of 'JoinInstruction' 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:
--
-- 'leftJoinKeyProperties', 'joinInstruction_leftJoinKeyProperties' - Join key properties of the left operand.
--
-- 'rightJoinKeyProperties', 'joinInstruction_rightJoinKeyProperties' - Join key properties of the right operand.
--
-- 'leftOperand', 'joinInstruction_leftOperand' - The operand on the left side of a join.
--
-- 'rightOperand', 'joinInstruction_rightOperand' - The operand on the right side of a join.
--
-- 'type'', 'joinInstruction_type' - The type of join that it is.
--
-- 'onClause', 'joinInstruction_onClause' - The join instructions provided in the @ON@ clause of a join.
newJoinInstruction ::
  -- | 'leftOperand'
  Prelude.Text ->
  -- | 'rightOperand'
  Prelude.Text ->
  -- | 'type''
  JoinType ->
  -- | 'onClause'
  Prelude.Text ->
  JoinInstruction
newJoinInstruction :: Text -> Text -> JoinType -> Text -> JoinInstruction
newJoinInstruction
  Text
pLeftOperand_
  Text
pRightOperand_
  JoinType
pType_
  Text
pOnClause_ =
    JoinInstruction'
      { $sel:leftJoinKeyProperties:JoinInstruction' :: Maybe JoinKeyProperties
leftJoinKeyProperties =
          forall a. Maybe a
Prelude.Nothing,
        $sel:rightJoinKeyProperties:JoinInstruction' :: Maybe JoinKeyProperties
rightJoinKeyProperties = forall a. Maybe a
Prelude.Nothing,
        $sel:leftOperand:JoinInstruction' :: Text
leftOperand = Text
pLeftOperand_,
        $sel:rightOperand:JoinInstruction' :: Text
rightOperand = Text
pRightOperand_,
        $sel:type':JoinInstruction' :: JoinType
type' = JoinType
pType_,
        $sel:onClause:JoinInstruction' :: Text
onClause = Text
pOnClause_
      }

-- | Join key properties of the left operand.
joinInstruction_leftJoinKeyProperties :: Lens.Lens' JoinInstruction (Prelude.Maybe JoinKeyProperties)
joinInstruction_leftJoinKeyProperties :: Lens' JoinInstruction (Maybe JoinKeyProperties)
joinInstruction_leftJoinKeyProperties = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\JoinInstruction' {Maybe JoinKeyProperties
leftJoinKeyProperties :: Maybe JoinKeyProperties
$sel:leftJoinKeyProperties:JoinInstruction' :: JoinInstruction -> Maybe JoinKeyProperties
leftJoinKeyProperties} -> Maybe JoinKeyProperties
leftJoinKeyProperties) (\s :: JoinInstruction
s@JoinInstruction' {} Maybe JoinKeyProperties
a -> JoinInstruction
s {$sel:leftJoinKeyProperties:JoinInstruction' :: Maybe JoinKeyProperties
leftJoinKeyProperties = Maybe JoinKeyProperties
a} :: JoinInstruction)

-- | Join key properties of the right operand.
joinInstruction_rightJoinKeyProperties :: Lens.Lens' JoinInstruction (Prelude.Maybe JoinKeyProperties)
joinInstruction_rightJoinKeyProperties :: Lens' JoinInstruction (Maybe JoinKeyProperties)
joinInstruction_rightJoinKeyProperties = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\JoinInstruction' {Maybe JoinKeyProperties
rightJoinKeyProperties :: Maybe JoinKeyProperties
$sel:rightJoinKeyProperties:JoinInstruction' :: JoinInstruction -> Maybe JoinKeyProperties
rightJoinKeyProperties} -> Maybe JoinKeyProperties
rightJoinKeyProperties) (\s :: JoinInstruction
s@JoinInstruction' {} Maybe JoinKeyProperties
a -> JoinInstruction
s {$sel:rightJoinKeyProperties:JoinInstruction' :: Maybe JoinKeyProperties
rightJoinKeyProperties = Maybe JoinKeyProperties
a} :: JoinInstruction)

-- | The operand on the left side of a join.
joinInstruction_leftOperand :: Lens.Lens' JoinInstruction Prelude.Text
joinInstruction_leftOperand :: Lens' JoinInstruction Text
joinInstruction_leftOperand = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\JoinInstruction' {Text
leftOperand :: Text
$sel:leftOperand:JoinInstruction' :: JoinInstruction -> Text
leftOperand} -> Text
leftOperand) (\s :: JoinInstruction
s@JoinInstruction' {} Text
a -> JoinInstruction
s {$sel:leftOperand:JoinInstruction' :: Text
leftOperand = Text
a} :: JoinInstruction)

-- | The operand on the right side of a join.
joinInstruction_rightOperand :: Lens.Lens' JoinInstruction Prelude.Text
joinInstruction_rightOperand :: Lens' JoinInstruction Text
joinInstruction_rightOperand = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\JoinInstruction' {Text
rightOperand :: Text
$sel:rightOperand:JoinInstruction' :: JoinInstruction -> Text
rightOperand} -> Text
rightOperand) (\s :: JoinInstruction
s@JoinInstruction' {} Text
a -> JoinInstruction
s {$sel:rightOperand:JoinInstruction' :: Text
rightOperand = Text
a} :: JoinInstruction)

-- | The type of join that it is.
joinInstruction_type :: Lens.Lens' JoinInstruction JoinType
joinInstruction_type :: Lens' JoinInstruction JoinType
joinInstruction_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\JoinInstruction' {JoinType
type' :: JoinType
$sel:type':JoinInstruction' :: JoinInstruction -> JoinType
type'} -> JoinType
type') (\s :: JoinInstruction
s@JoinInstruction' {} JoinType
a -> JoinInstruction
s {$sel:type':JoinInstruction' :: JoinType
type' = JoinType
a} :: JoinInstruction)

-- | The join instructions provided in the @ON@ clause of a join.
joinInstruction_onClause :: Lens.Lens' JoinInstruction Prelude.Text
joinInstruction_onClause :: Lens' JoinInstruction Text
joinInstruction_onClause = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\JoinInstruction' {Text
onClause :: Text
$sel:onClause:JoinInstruction' :: JoinInstruction -> Text
onClause} -> Text
onClause) (\s :: JoinInstruction
s@JoinInstruction' {} Text
a -> JoinInstruction
s {$sel:onClause:JoinInstruction' :: Text
onClause = Text
a} :: JoinInstruction)

instance Data.FromJSON JoinInstruction where
  parseJSON :: Value -> Parser JoinInstruction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"JoinInstruction"
      ( \Object
x ->
          Maybe JoinKeyProperties
-> Maybe JoinKeyProperties
-> Text
-> Text
-> JoinType
-> Text
-> JoinInstruction
JoinInstruction'
            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
"LeftJoinKeyProperties")
            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
"RightJoinKeyProperties")
            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
"LeftOperand")
            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
"RightOperand")
            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
"Type")
            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
"OnClause")
      )

instance Prelude.Hashable JoinInstruction where
  hashWithSalt :: Int -> JoinInstruction -> Int
hashWithSalt Int
_salt JoinInstruction' {Maybe JoinKeyProperties
Text
JoinType
onClause :: Text
type' :: JoinType
rightOperand :: Text
leftOperand :: Text
rightJoinKeyProperties :: Maybe JoinKeyProperties
leftJoinKeyProperties :: Maybe JoinKeyProperties
$sel:onClause:JoinInstruction' :: JoinInstruction -> Text
$sel:type':JoinInstruction' :: JoinInstruction -> JoinType
$sel:rightOperand:JoinInstruction' :: JoinInstruction -> Text
$sel:leftOperand:JoinInstruction' :: JoinInstruction -> Text
$sel:rightJoinKeyProperties:JoinInstruction' :: JoinInstruction -> Maybe JoinKeyProperties
$sel:leftJoinKeyProperties:JoinInstruction' :: JoinInstruction -> Maybe JoinKeyProperties
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe JoinKeyProperties
leftJoinKeyProperties
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe JoinKeyProperties
rightJoinKeyProperties
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
leftOperand
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
rightOperand
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` JoinType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
onClause

instance Prelude.NFData JoinInstruction where
  rnf :: JoinInstruction -> ()
rnf JoinInstruction' {Maybe JoinKeyProperties
Text
JoinType
onClause :: Text
type' :: JoinType
rightOperand :: Text
leftOperand :: Text
rightJoinKeyProperties :: Maybe JoinKeyProperties
leftJoinKeyProperties :: Maybe JoinKeyProperties
$sel:onClause:JoinInstruction' :: JoinInstruction -> Text
$sel:type':JoinInstruction' :: JoinInstruction -> JoinType
$sel:rightOperand:JoinInstruction' :: JoinInstruction -> Text
$sel:leftOperand:JoinInstruction' :: JoinInstruction -> Text
$sel:rightJoinKeyProperties:JoinInstruction' :: JoinInstruction -> Maybe JoinKeyProperties
$sel:leftJoinKeyProperties:JoinInstruction' :: JoinInstruction -> Maybe JoinKeyProperties
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe JoinKeyProperties
leftJoinKeyProperties
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe JoinKeyProperties
rightJoinKeyProperties
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
leftOperand
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
rightOperand
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf JoinType
type'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
onClause

instance Data.ToJSON JoinInstruction where
  toJSON :: JoinInstruction -> Value
toJSON JoinInstruction' {Maybe JoinKeyProperties
Text
JoinType
onClause :: Text
type' :: JoinType
rightOperand :: Text
leftOperand :: Text
rightJoinKeyProperties :: Maybe JoinKeyProperties
leftJoinKeyProperties :: Maybe JoinKeyProperties
$sel:onClause:JoinInstruction' :: JoinInstruction -> Text
$sel:type':JoinInstruction' :: JoinInstruction -> JoinType
$sel:rightOperand:JoinInstruction' :: JoinInstruction -> Text
$sel:leftOperand:JoinInstruction' :: JoinInstruction -> Text
$sel:rightJoinKeyProperties:JoinInstruction' :: JoinInstruction -> Maybe JoinKeyProperties
$sel:leftJoinKeyProperties:JoinInstruction' :: JoinInstruction -> Maybe JoinKeyProperties
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"LeftJoinKeyProperties" 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 JoinKeyProperties
leftJoinKeyProperties,
            (Key
"RightJoinKeyProperties" 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 JoinKeyProperties
rightJoinKeyProperties,
            forall a. a -> Maybe a
Prelude.Just (Key
"LeftOperand" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
leftOperand),
            forall a. a -> Maybe a
Prelude.Just (Key
"RightOperand" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
rightOperand),
            forall a. a -> Maybe a
Prelude.Just (Key
"Type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= JoinType
type'),
            forall a. a -> Maybe a
Prelude.Just (Key
"OnClause" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
onClause)
          ]
      )