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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.QuickSight.Types.CalculatedColumn

-- | A transform operation that creates calculated columns. Columns created
-- in one such operation form a lexical closure.
--
-- /See:/ 'newCreateColumnsOperation' smart constructor.
data CreateColumnsOperation = CreateColumnsOperation'
  { -- | Calculated columns to create.
    CreateColumnsOperation -> NonEmpty CalculatedColumn
columns :: Prelude.NonEmpty CalculatedColumn
  }
  deriving (CreateColumnsOperation -> CreateColumnsOperation -> Bool
(CreateColumnsOperation -> CreateColumnsOperation -> Bool)
-> (CreateColumnsOperation -> CreateColumnsOperation -> Bool)
-> Eq CreateColumnsOperation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateColumnsOperation -> CreateColumnsOperation -> Bool
$c/= :: CreateColumnsOperation -> CreateColumnsOperation -> Bool
== :: CreateColumnsOperation -> CreateColumnsOperation -> Bool
$c== :: CreateColumnsOperation -> CreateColumnsOperation -> Bool
Prelude.Eq, ReadPrec [CreateColumnsOperation]
ReadPrec CreateColumnsOperation
Int -> ReadS CreateColumnsOperation
ReadS [CreateColumnsOperation]
(Int -> ReadS CreateColumnsOperation)
-> ReadS [CreateColumnsOperation]
-> ReadPrec CreateColumnsOperation
-> ReadPrec [CreateColumnsOperation]
-> Read CreateColumnsOperation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateColumnsOperation]
$creadListPrec :: ReadPrec [CreateColumnsOperation]
readPrec :: ReadPrec CreateColumnsOperation
$creadPrec :: ReadPrec CreateColumnsOperation
readList :: ReadS [CreateColumnsOperation]
$creadList :: ReadS [CreateColumnsOperation]
readsPrec :: Int -> ReadS CreateColumnsOperation
$creadsPrec :: Int -> ReadS CreateColumnsOperation
Prelude.Read, Int -> CreateColumnsOperation -> ShowS
[CreateColumnsOperation] -> ShowS
CreateColumnsOperation -> String
(Int -> CreateColumnsOperation -> ShowS)
-> (CreateColumnsOperation -> String)
-> ([CreateColumnsOperation] -> ShowS)
-> Show CreateColumnsOperation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateColumnsOperation] -> ShowS
$cshowList :: [CreateColumnsOperation] -> ShowS
show :: CreateColumnsOperation -> String
$cshow :: CreateColumnsOperation -> String
showsPrec :: Int -> CreateColumnsOperation -> ShowS
$cshowsPrec :: Int -> CreateColumnsOperation -> ShowS
Prelude.Show, (forall x. CreateColumnsOperation -> Rep CreateColumnsOperation x)
-> (forall x.
    Rep CreateColumnsOperation x -> CreateColumnsOperation)
-> Generic CreateColumnsOperation
forall x. Rep CreateColumnsOperation x -> CreateColumnsOperation
forall x. CreateColumnsOperation -> Rep CreateColumnsOperation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateColumnsOperation x -> CreateColumnsOperation
$cfrom :: forall x. CreateColumnsOperation -> Rep CreateColumnsOperation x
Prelude.Generic)

-- |
-- Create a value of 'CreateColumnsOperation' 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:
--
-- 'columns', 'createColumnsOperation_columns' - Calculated columns to create.
newCreateColumnsOperation ::
  -- | 'columns'
  Prelude.NonEmpty CalculatedColumn ->
  CreateColumnsOperation
newCreateColumnsOperation :: NonEmpty CalculatedColumn -> CreateColumnsOperation
newCreateColumnsOperation NonEmpty CalculatedColumn
pColumns_ =
  CreateColumnsOperation' :: NonEmpty CalculatedColumn -> CreateColumnsOperation
CreateColumnsOperation'
    { $sel:columns:CreateColumnsOperation' :: NonEmpty CalculatedColumn
columns =
        Tagged
  (NonEmpty CalculatedColumn) (Identity (NonEmpty CalculatedColumn))
-> Tagged
     (NonEmpty CalculatedColumn) (Identity (NonEmpty CalculatedColumn))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty CalculatedColumn) (Identity (NonEmpty CalculatedColumn))
 -> Tagged
      (NonEmpty CalculatedColumn) (Identity (NonEmpty CalculatedColumn)))
-> NonEmpty CalculatedColumn -> NonEmpty CalculatedColumn
forall t b. AReview t b -> b -> t
Lens.# NonEmpty CalculatedColumn
pColumns_
    }

-- | Calculated columns to create.
createColumnsOperation_columns :: Lens.Lens' CreateColumnsOperation (Prelude.NonEmpty CalculatedColumn)
createColumnsOperation_columns :: (NonEmpty CalculatedColumn -> f (NonEmpty CalculatedColumn))
-> CreateColumnsOperation -> f CreateColumnsOperation
createColumnsOperation_columns = (CreateColumnsOperation -> NonEmpty CalculatedColumn)
-> (CreateColumnsOperation
    -> NonEmpty CalculatedColumn -> CreateColumnsOperation)
-> Lens
     CreateColumnsOperation
     CreateColumnsOperation
     (NonEmpty CalculatedColumn)
     (NonEmpty CalculatedColumn)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateColumnsOperation' {NonEmpty CalculatedColumn
columns :: NonEmpty CalculatedColumn
$sel:columns:CreateColumnsOperation' :: CreateColumnsOperation -> NonEmpty CalculatedColumn
columns} -> NonEmpty CalculatedColumn
columns) (\s :: CreateColumnsOperation
s@CreateColumnsOperation' {} NonEmpty CalculatedColumn
a -> CreateColumnsOperation
s {$sel:columns:CreateColumnsOperation' :: NonEmpty CalculatedColumn
columns = NonEmpty CalculatedColumn
a} :: CreateColumnsOperation) ((NonEmpty CalculatedColumn -> f (NonEmpty CalculatedColumn))
 -> CreateColumnsOperation -> f CreateColumnsOperation)
-> ((NonEmpty CalculatedColumn -> f (NonEmpty CalculatedColumn))
    -> NonEmpty CalculatedColumn -> f (NonEmpty CalculatedColumn))
-> (NonEmpty CalculatedColumn -> f (NonEmpty CalculatedColumn))
-> CreateColumnsOperation
-> f CreateColumnsOperation
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty CalculatedColumn -> f (NonEmpty CalculatedColumn))
-> NonEmpty CalculatedColumn -> f (NonEmpty CalculatedColumn)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable CreateColumnsOperation

instance Prelude.NFData CreateColumnsOperation

instance Core.ToJSON CreateColumnsOperation where
  toJSON :: CreateColumnsOperation -> Value
toJSON CreateColumnsOperation' {NonEmpty CalculatedColumn
columns :: NonEmpty CalculatedColumn
$sel:columns:CreateColumnsOperation' :: CreateColumnsOperation -> NonEmpty CalculatedColumn
..} =
    [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
"Columns" Text -> NonEmpty CalculatedColumn -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty CalculatedColumn
columns)]
      )