{-# 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.ProjectOperation
-- 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.ProjectOperation where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A transform operation that projects columns. Operations that come after
-- a projection can only refer to projected columns.
--
-- /See:/ 'newProjectOperation' smart constructor.
data ProjectOperation = ProjectOperation'
  { -- | Projected columns.
    ProjectOperation -> NonEmpty Text
projectedColumns :: Prelude.NonEmpty Prelude.Text
  }
  deriving (ProjectOperation -> ProjectOperation -> Bool
(ProjectOperation -> ProjectOperation -> Bool)
-> (ProjectOperation -> ProjectOperation -> Bool)
-> Eq ProjectOperation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProjectOperation -> ProjectOperation -> Bool
$c/= :: ProjectOperation -> ProjectOperation -> Bool
== :: ProjectOperation -> ProjectOperation -> Bool
$c== :: ProjectOperation -> ProjectOperation -> Bool
Prelude.Eq, ReadPrec [ProjectOperation]
ReadPrec ProjectOperation
Int -> ReadS ProjectOperation
ReadS [ProjectOperation]
(Int -> ReadS ProjectOperation)
-> ReadS [ProjectOperation]
-> ReadPrec ProjectOperation
-> ReadPrec [ProjectOperation]
-> Read ProjectOperation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ProjectOperation]
$creadListPrec :: ReadPrec [ProjectOperation]
readPrec :: ReadPrec ProjectOperation
$creadPrec :: ReadPrec ProjectOperation
readList :: ReadS [ProjectOperation]
$creadList :: ReadS [ProjectOperation]
readsPrec :: Int -> ReadS ProjectOperation
$creadsPrec :: Int -> ReadS ProjectOperation
Prelude.Read, Int -> ProjectOperation -> ShowS
[ProjectOperation] -> ShowS
ProjectOperation -> String
(Int -> ProjectOperation -> ShowS)
-> (ProjectOperation -> String)
-> ([ProjectOperation] -> ShowS)
-> Show ProjectOperation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProjectOperation] -> ShowS
$cshowList :: [ProjectOperation] -> ShowS
show :: ProjectOperation -> String
$cshow :: ProjectOperation -> String
showsPrec :: Int -> ProjectOperation -> ShowS
$cshowsPrec :: Int -> ProjectOperation -> ShowS
Prelude.Show, (forall x. ProjectOperation -> Rep ProjectOperation x)
-> (forall x. Rep ProjectOperation x -> ProjectOperation)
-> Generic ProjectOperation
forall x. Rep ProjectOperation x -> ProjectOperation
forall x. ProjectOperation -> Rep ProjectOperation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProjectOperation x -> ProjectOperation
$cfrom :: forall x. ProjectOperation -> Rep ProjectOperation x
Prelude.Generic)

-- |
-- Create a value of 'ProjectOperation' 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:
--
-- 'projectedColumns', 'projectOperation_projectedColumns' - Projected columns.
newProjectOperation ::
  -- | 'projectedColumns'
  Prelude.NonEmpty Prelude.Text ->
  ProjectOperation
newProjectOperation :: NonEmpty Text -> ProjectOperation
newProjectOperation NonEmpty Text
pProjectedColumns_ =
  ProjectOperation' :: NonEmpty Text -> ProjectOperation
ProjectOperation'
    { $sel:projectedColumns:ProjectOperation' :: NonEmpty Text
projectedColumns =
        Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pProjectedColumns_
    }

-- | Projected columns.
projectOperation_projectedColumns :: Lens.Lens' ProjectOperation (Prelude.NonEmpty Prelude.Text)
projectOperation_projectedColumns :: (NonEmpty Text -> f (NonEmpty Text))
-> ProjectOperation -> f ProjectOperation
projectOperation_projectedColumns = (ProjectOperation -> NonEmpty Text)
-> (ProjectOperation -> NonEmpty Text -> ProjectOperation)
-> Lens
     ProjectOperation ProjectOperation (NonEmpty Text) (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProjectOperation' {NonEmpty Text
projectedColumns :: NonEmpty Text
$sel:projectedColumns:ProjectOperation' :: ProjectOperation -> NonEmpty Text
projectedColumns} -> NonEmpty Text
projectedColumns) (\s :: ProjectOperation
s@ProjectOperation' {} NonEmpty Text
a -> ProjectOperation
s {$sel:projectedColumns:ProjectOperation' :: NonEmpty Text
projectedColumns = NonEmpty Text
a} :: ProjectOperation) ((NonEmpty Text -> f (NonEmpty Text))
 -> ProjectOperation -> f ProjectOperation)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> ProjectOperation
-> f ProjectOperation
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON ProjectOperation where
  parseJSON :: Value -> Parser ProjectOperation
parseJSON =
    String
-> (Object -> Parser ProjectOperation)
-> Value
-> Parser ProjectOperation
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ProjectOperation"
      ( \Object
x ->
          NonEmpty Text -> ProjectOperation
ProjectOperation'
            (NonEmpty Text -> ProjectOperation)
-> Parser (NonEmpty Text) -> Parser ProjectOperation
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (NonEmpty Text)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ProjectedColumns")
      )

instance Prelude.Hashable ProjectOperation

instance Prelude.NFData ProjectOperation

instance Core.ToJSON ProjectOperation where
  toJSON :: ProjectOperation -> Value
toJSON ProjectOperation' {NonEmpty Text
projectedColumns :: NonEmpty Text
$sel:projectedColumns:ProjectOperation' :: ProjectOperation -> NonEmpty Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ProjectedColumns" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
projectedColumns)
          ]
      )