{-# 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-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.QuickSight.Types.JoinInstruction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 right operand.
    JoinInstruction -> Maybe JoinKeyProperties
rightJoinKeyProperties :: Prelude.Maybe JoinKeyProperties,
    -- | Join key properties of the left operand.
    JoinInstruction -> Maybe JoinKeyProperties
leftJoinKeyProperties :: 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
(JoinInstruction -> JoinInstruction -> Bool)
-> (JoinInstruction -> JoinInstruction -> Bool)
-> Eq JoinInstruction
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]
(Int -> ReadS JoinInstruction)
-> ReadS [JoinInstruction]
-> ReadPrec JoinInstruction
-> ReadPrec [JoinInstruction]
-> Read 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
(Int -> JoinInstruction -> ShowS)
-> (JoinInstruction -> String)
-> ([JoinInstruction] -> ShowS)
-> Show JoinInstruction
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. JoinInstruction -> Rep JoinInstruction x)
-> (forall x. Rep JoinInstruction x -> JoinInstruction)
-> Generic JoinInstruction
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:
--
-- 'rightJoinKeyProperties', 'joinInstruction_rightJoinKeyProperties' - Join key properties of the right operand.
--
-- 'leftJoinKeyProperties', 'joinInstruction_leftJoinKeyProperties' - Join key properties of the left 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' :: Maybe JoinKeyProperties
-> Maybe JoinKeyProperties
-> Text
-> Text
-> JoinType
-> Text
-> JoinInstruction
JoinInstruction'
      { $sel:rightJoinKeyProperties:JoinInstruction' :: Maybe JoinKeyProperties
rightJoinKeyProperties =
          Maybe JoinKeyProperties
forall a. Maybe a
Prelude.Nothing,
        $sel:leftJoinKeyProperties:JoinInstruction' :: Maybe JoinKeyProperties
leftJoinKeyProperties = Maybe JoinKeyProperties
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 right operand.
joinInstruction_rightJoinKeyProperties :: Lens.Lens' JoinInstruction (Prelude.Maybe JoinKeyProperties)
joinInstruction_rightJoinKeyProperties :: (Maybe JoinKeyProperties -> f (Maybe JoinKeyProperties))
-> JoinInstruction -> f JoinInstruction
joinInstruction_rightJoinKeyProperties = (JoinInstruction -> Maybe JoinKeyProperties)
-> (JoinInstruction -> Maybe JoinKeyProperties -> JoinInstruction)
-> Lens
     JoinInstruction
     JoinInstruction
     (Maybe JoinKeyProperties)
     (Maybe JoinKeyProperties)
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)

-- | Join key properties of the left operand.
joinInstruction_leftJoinKeyProperties :: Lens.Lens' JoinInstruction (Prelude.Maybe JoinKeyProperties)
joinInstruction_leftJoinKeyProperties :: (Maybe JoinKeyProperties -> f (Maybe JoinKeyProperties))
-> JoinInstruction -> f JoinInstruction
joinInstruction_leftJoinKeyProperties = (JoinInstruction -> Maybe JoinKeyProperties)
-> (JoinInstruction -> Maybe JoinKeyProperties -> JoinInstruction)
-> Lens
     JoinInstruction
     JoinInstruction
     (Maybe JoinKeyProperties)
     (Maybe JoinKeyProperties)
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)

-- | The operand on the left side of a join.
joinInstruction_leftOperand :: Lens.Lens' JoinInstruction Prelude.Text
joinInstruction_leftOperand :: (Text -> f Text) -> JoinInstruction -> f JoinInstruction
joinInstruction_leftOperand = (JoinInstruction -> Text)
-> (JoinInstruction -> Text -> JoinInstruction)
-> Lens JoinInstruction JoinInstruction Text Text
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 :: (Text -> f Text) -> JoinInstruction -> f JoinInstruction
joinInstruction_rightOperand = (JoinInstruction -> Text)
-> (JoinInstruction -> Text -> JoinInstruction)
-> Lens JoinInstruction JoinInstruction Text Text
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 :: (JoinType -> f JoinType) -> JoinInstruction -> f JoinInstruction
joinInstruction_type = (JoinInstruction -> JoinType)
-> (JoinInstruction -> JoinType -> JoinInstruction)
-> Lens JoinInstruction JoinInstruction JoinType JoinType
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 :: (Text -> f Text) -> JoinInstruction -> f JoinInstruction
joinInstruction_onClause = (JoinInstruction -> Text)
-> (JoinInstruction -> Text -> JoinInstruction)
-> Lens JoinInstruction JoinInstruction Text Text
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 Core.FromJSON JoinInstruction where
  parseJSON :: Value -> Parser JoinInstruction
parseJSON =
    String
-> (Object -> Parser JoinInstruction)
-> Value
-> Parser JoinInstruction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"JoinInstruction"
      ( \Object
x ->
          Maybe JoinKeyProperties
-> Maybe JoinKeyProperties
-> Text
-> Text
-> JoinType
-> Text
-> JoinInstruction
JoinInstruction'
            (Maybe JoinKeyProperties
 -> Maybe JoinKeyProperties
 -> Text
 -> Text
 -> JoinType
 -> Text
 -> JoinInstruction)
-> Parser (Maybe JoinKeyProperties)
-> Parser
     (Maybe JoinKeyProperties
      -> Text -> Text -> JoinType -> Text -> JoinInstruction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe JoinKeyProperties)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RightJoinKeyProperties")
            Parser
  (Maybe JoinKeyProperties
   -> Text -> Text -> JoinType -> Text -> JoinInstruction)
-> Parser (Maybe JoinKeyProperties)
-> Parser (Text -> Text -> JoinType -> Text -> JoinInstruction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe JoinKeyProperties)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"LeftJoinKeyProperties")
            Parser (Text -> Text -> JoinType -> Text -> JoinInstruction)
-> Parser Text
-> Parser (Text -> JoinType -> Text -> JoinInstruction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"LeftOperand")
            Parser (Text -> JoinType -> Text -> JoinInstruction)
-> Parser Text -> Parser (JoinType -> Text -> JoinInstruction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"RightOperand")
            Parser (JoinType -> Text -> JoinInstruction)
-> Parser JoinType -> Parser (Text -> JoinInstruction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser JoinType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type")
            Parser (Text -> JoinInstruction)
-> Parser Text -> Parser JoinInstruction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"OnClause")
      )

instance Prelude.Hashable JoinInstruction

instance Prelude.NFData JoinInstruction

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