{-# 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-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.CastColumnTypeOperation 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.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
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]
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
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. 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'
      { $sel:format:CastColumnTypeOperation' :: Maybe Text
format = 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 :: Lens' CastColumnTypeOperation (Maybe Text)
castColumnTypeOperation_format = 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 :: Lens' CastColumnTypeOperation Text
castColumnTypeOperation_columnName = 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 :: Lens' CastColumnTypeOperation ColumnDataType
castColumnTypeOperation_newColumnType = 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 Data.FromJSON CastColumnTypeOperation where
  parseJSON :: Value -> Parser CastColumnTypeOperation
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CastColumnTypeOperation"
      ( \Object
x ->
          Maybe Text -> Text -> ColumnDataType -> CastColumnTypeOperation
CastColumnTypeOperation'
            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
"Format")
            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
"ColumnName")
            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
"NewColumnType")
      )

instance Prelude.Hashable CastColumnTypeOperation where
  hashWithSalt :: Int -> CastColumnTypeOperation -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
format
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
columnName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ColumnDataType
newColumnType'

instance Prelude.NFData CastColumnTypeOperation where
  rnf :: CastColumnTypeOperation -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
format
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
columnName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ColumnDataType
newColumnType'

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Format" 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 Text
format,
            forall a. a -> Maybe a
Prelude.Just (Key
"ColumnName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
columnName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"NewColumnType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ColumnDataType
newColumnType')
          ]
      )