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

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

-- | A transform operation that casts a column to a different type.
--
-- /See:/ 'newCastColumnTypeOperation' smart constructor.
data CastColumnTypeOperation = CastColumnTypeOperation'
  { -- | When casting a column from string to datetime type, you can supply a
    -- string in a format supported by Amazon QuickSight to denote the source
    -- data format.
    CastColumnTypeOperation -> Maybe Text
format :: Prelude.Maybe Prelude.Text,
    -- | Column name.
    CastColumnTypeOperation -> Text
columnName :: Prelude.Text,
    -- | New column data type.
    CastColumnTypeOperation -> ColumnDataType
newColumnType' :: ColumnDataType
  }
  deriving (CastColumnTypeOperation -> CastColumnTypeOperation -> Bool
(CastColumnTypeOperation -> CastColumnTypeOperation -> Bool)
-> (CastColumnTypeOperation -> CastColumnTypeOperation -> Bool)
-> Eq CastColumnTypeOperation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CastColumnTypeOperation -> CastColumnTypeOperation -> Bool
$c/= :: CastColumnTypeOperation -> CastColumnTypeOperation -> Bool
== :: CastColumnTypeOperation -> CastColumnTypeOperation -> Bool
$c== :: CastColumnTypeOperation -> CastColumnTypeOperation -> Bool
Prelude.Eq, ReadPrec [CastColumnTypeOperation]
ReadPrec CastColumnTypeOperation
Int -> ReadS CastColumnTypeOperation
ReadS [CastColumnTypeOperation]
(Int -> ReadS CastColumnTypeOperation)
-> ReadS [CastColumnTypeOperation]
-> ReadPrec CastColumnTypeOperation
-> ReadPrec [CastColumnTypeOperation]
-> Read CastColumnTypeOperation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CastColumnTypeOperation]
$creadListPrec :: ReadPrec [CastColumnTypeOperation]
readPrec :: ReadPrec CastColumnTypeOperation
$creadPrec :: ReadPrec CastColumnTypeOperation
readList :: ReadS [CastColumnTypeOperation]
$creadList :: ReadS [CastColumnTypeOperation]
readsPrec :: Int -> ReadS CastColumnTypeOperation
$creadsPrec :: Int -> ReadS CastColumnTypeOperation
Prelude.Read, Int -> CastColumnTypeOperation -> ShowS
[CastColumnTypeOperation] -> ShowS
CastColumnTypeOperation -> String
(Int -> CastColumnTypeOperation -> ShowS)
-> (CastColumnTypeOperation -> String)
-> ([CastColumnTypeOperation] -> ShowS)
-> Show CastColumnTypeOperation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CastColumnTypeOperation] -> ShowS
$cshowList :: [CastColumnTypeOperation] -> ShowS
show :: CastColumnTypeOperation -> String
$cshow :: CastColumnTypeOperation -> String
showsPrec :: Int -> CastColumnTypeOperation -> ShowS
$cshowsPrec :: Int -> CastColumnTypeOperation -> ShowS
Prelude.Show, (forall x.
 CastColumnTypeOperation -> Rep CastColumnTypeOperation x)
-> (forall x.
    Rep CastColumnTypeOperation x -> CastColumnTypeOperation)
-> Generic CastColumnTypeOperation
forall x. Rep CastColumnTypeOperation x -> CastColumnTypeOperation
forall x. CastColumnTypeOperation -> Rep CastColumnTypeOperation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CastColumnTypeOperation x -> CastColumnTypeOperation
$cfrom :: forall x. CastColumnTypeOperation -> Rep CastColumnTypeOperation x
Prelude.Generic)

-- |
-- Create a value of 'CastColumnTypeOperation' 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:
--
-- 'format', 'castColumnTypeOperation_format' - When casting a column from string to datetime type, you can supply a
-- string in a format supported by Amazon QuickSight to denote the source
-- data format.
--
-- 'columnName', 'castColumnTypeOperation_columnName' - Column name.
--
-- 'newColumnType'', 'castColumnTypeOperation_newColumnType' - New column data type.
newCastColumnTypeOperation ::
  -- | 'columnName'
  Prelude.Text ->
  -- | 'newColumnType''
  ColumnDataType ->
  CastColumnTypeOperation
newCastColumnTypeOperation :: Text -> ColumnDataType -> CastColumnTypeOperation
newCastColumnTypeOperation
  Text
pColumnName_
  ColumnDataType
pNewColumnType_ =
    CastColumnTypeOperation' :: Maybe Text -> Text -> ColumnDataType -> CastColumnTypeOperation
CastColumnTypeOperation'
      { $sel:format:CastColumnTypeOperation' :: Maybe Text
format = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:columnName:CastColumnTypeOperation' :: Text
columnName = Text
pColumnName_,
        $sel:newColumnType':CastColumnTypeOperation' :: ColumnDataType
newColumnType' = ColumnDataType
pNewColumnType_
      }

-- | When casting a column from string to datetime type, you can supply a
-- string in a format supported by Amazon QuickSight to denote the source
-- data format.
castColumnTypeOperation_format :: Lens.Lens' CastColumnTypeOperation (Prelude.Maybe Prelude.Text)
castColumnTypeOperation_format :: (Maybe Text -> f (Maybe Text))
-> CastColumnTypeOperation -> f CastColumnTypeOperation
castColumnTypeOperation_format = (CastColumnTypeOperation -> Maybe Text)
-> (CastColumnTypeOperation
    -> Maybe Text -> CastColumnTypeOperation)
-> Lens
     CastColumnTypeOperation
     CastColumnTypeOperation
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CastColumnTypeOperation' {Maybe Text
format :: Maybe Text
$sel:format:CastColumnTypeOperation' :: CastColumnTypeOperation -> Maybe Text
format} -> Maybe Text
format) (\s :: CastColumnTypeOperation
s@CastColumnTypeOperation' {} Maybe Text
a -> CastColumnTypeOperation
s {$sel:format:CastColumnTypeOperation' :: Maybe Text
format = Maybe Text
a} :: CastColumnTypeOperation)

-- | Column name.
castColumnTypeOperation_columnName :: Lens.Lens' CastColumnTypeOperation Prelude.Text
castColumnTypeOperation_columnName :: (Text -> f Text)
-> CastColumnTypeOperation -> f CastColumnTypeOperation
castColumnTypeOperation_columnName = (CastColumnTypeOperation -> Text)
-> (CastColumnTypeOperation -> Text -> CastColumnTypeOperation)
-> Lens CastColumnTypeOperation CastColumnTypeOperation Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CastColumnTypeOperation' {Text
columnName :: Text
$sel:columnName:CastColumnTypeOperation' :: CastColumnTypeOperation -> Text
columnName} -> Text
columnName) (\s :: CastColumnTypeOperation
s@CastColumnTypeOperation' {} Text
a -> CastColumnTypeOperation
s {$sel:columnName:CastColumnTypeOperation' :: Text
columnName = Text
a} :: CastColumnTypeOperation)

-- | New column data type.
castColumnTypeOperation_newColumnType :: Lens.Lens' CastColumnTypeOperation ColumnDataType
castColumnTypeOperation_newColumnType :: (ColumnDataType -> f ColumnDataType)
-> CastColumnTypeOperation -> f CastColumnTypeOperation
castColumnTypeOperation_newColumnType = (CastColumnTypeOperation -> ColumnDataType)
-> (CastColumnTypeOperation
    -> ColumnDataType -> CastColumnTypeOperation)
-> Lens
     CastColumnTypeOperation
     CastColumnTypeOperation
     ColumnDataType
     ColumnDataType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CastColumnTypeOperation' {ColumnDataType
newColumnType' :: ColumnDataType
$sel:newColumnType':CastColumnTypeOperation' :: CastColumnTypeOperation -> ColumnDataType
newColumnType'} -> ColumnDataType
newColumnType') (\s :: CastColumnTypeOperation
s@CastColumnTypeOperation' {} ColumnDataType
a -> CastColumnTypeOperation
s {$sel:newColumnType':CastColumnTypeOperation' :: ColumnDataType
newColumnType' = ColumnDataType
a} :: CastColumnTypeOperation)

instance Core.FromJSON CastColumnTypeOperation where
  parseJSON :: Value -> Parser CastColumnTypeOperation
parseJSON =
    String
-> (Object -> Parser CastColumnTypeOperation)
-> Value
-> Parser CastColumnTypeOperation
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CastColumnTypeOperation"
      ( \Object
x ->
          Maybe Text -> Text -> ColumnDataType -> CastColumnTypeOperation
CastColumnTypeOperation'
            (Maybe Text -> Text -> ColumnDataType -> CastColumnTypeOperation)
-> Parser (Maybe Text)
-> Parser (Text -> ColumnDataType -> CastColumnTypeOperation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Format")
            Parser (Text -> ColumnDataType -> CastColumnTypeOperation)
-> Parser Text
-> Parser (ColumnDataType -> CastColumnTypeOperation)
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
"ColumnName")
            Parser (ColumnDataType -> CastColumnTypeOperation)
-> Parser ColumnDataType -> Parser CastColumnTypeOperation
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ColumnDataType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"NewColumnType")
      )

instance Prelude.Hashable CastColumnTypeOperation

instance Prelude.NFData CastColumnTypeOperation

instance Core.ToJSON CastColumnTypeOperation where
  toJSON :: CastColumnTypeOperation -> Value
toJSON CastColumnTypeOperation' {Maybe Text
Text
ColumnDataType
newColumnType' :: ColumnDataType
columnName :: Text
format :: Maybe Text
$sel:newColumnType':CastColumnTypeOperation' :: CastColumnTypeOperation -> ColumnDataType
$sel:columnName:CastColumnTypeOperation' :: CastColumnTypeOperation -> Text
$sel:format:CastColumnTypeOperation' :: CastColumnTypeOperation -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Format" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
format,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ColumnName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
columnName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"NewColumnType" Text -> ColumnDataType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ColumnDataType
newColumnType')
          ]
      )