{-# 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.ColorScale
-- 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.ColorScale 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.ColorFillType
import Amazonka.QuickSight.Types.DataColor

-- | Determines the color scale that is applied to the visual.
--
-- /See:/ 'newColorScale' smart constructor.
data ColorScale = ColorScale'
  { -- | Determines the color that is applied to null values.
    ColorScale -> Maybe DataColor
nullValueColor :: Prelude.Maybe DataColor,
    -- | Determines the list of colors that are applied to the visual.
    ColorScale -> NonEmpty DataColor
colors :: Prelude.NonEmpty DataColor,
    -- | Determines the color fill type.
    ColorScale -> ColorFillType
colorFillType :: ColorFillType
  }
  deriving (ColorScale -> ColorScale -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ColorScale -> ColorScale -> Bool
$c/= :: ColorScale -> ColorScale -> Bool
== :: ColorScale -> ColorScale -> Bool
$c== :: ColorScale -> ColorScale -> Bool
Prelude.Eq, ReadPrec [ColorScale]
ReadPrec ColorScale
Int -> ReadS ColorScale
ReadS [ColorScale]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ColorScale]
$creadListPrec :: ReadPrec [ColorScale]
readPrec :: ReadPrec ColorScale
$creadPrec :: ReadPrec ColorScale
readList :: ReadS [ColorScale]
$creadList :: ReadS [ColorScale]
readsPrec :: Int -> ReadS ColorScale
$creadsPrec :: Int -> ReadS ColorScale
Prelude.Read, Int -> ColorScale -> ShowS
[ColorScale] -> ShowS
ColorScale -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColorScale] -> ShowS
$cshowList :: [ColorScale] -> ShowS
show :: ColorScale -> String
$cshow :: ColorScale -> String
showsPrec :: Int -> ColorScale -> ShowS
$cshowsPrec :: Int -> ColorScale -> ShowS
Prelude.Show, forall x. Rep ColorScale x -> ColorScale
forall x. ColorScale -> Rep ColorScale x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ColorScale x -> ColorScale
$cfrom :: forall x. ColorScale -> Rep ColorScale x
Prelude.Generic)

-- |
-- Create a value of 'ColorScale' 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:
--
-- 'nullValueColor', 'colorScale_nullValueColor' - Determines the color that is applied to null values.
--
-- 'colors', 'colorScale_colors' - Determines the list of colors that are applied to the visual.
--
-- 'colorFillType', 'colorScale_colorFillType' - Determines the color fill type.
newColorScale ::
  -- | 'colors'
  Prelude.NonEmpty DataColor ->
  -- | 'colorFillType'
  ColorFillType ->
  ColorScale
newColorScale :: NonEmpty DataColor -> ColorFillType -> ColorScale
newColorScale NonEmpty DataColor
pColors_ ColorFillType
pColorFillType_ =
  ColorScale'
    { $sel:nullValueColor:ColorScale' :: Maybe DataColor
nullValueColor = forall a. Maybe a
Prelude.Nothing,
      $sel:colors:ColorScale' :: NonEmpty DataColor
colors = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty DataColor
pColors_,
      $sel:colorFillType:ColorScale' :: ColorFillType
colorFillType = ColorFillType
pColorFillType_
    }

-- | Determines the color that is applied to null values.
colorScale_nullValueColor :: Lens.Lens' ColorScale (Prelude.Maybe DataColor)
colorScale_nullValueColor :: Lens' ColorScale (Maybe DataColor)
colorScale_nullValueColor = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ColorScale' {Maybe DataColor
nullValueColor :: Maybe DataColor
$sel:nullValueColor:ColorScale' :: ColorScale -> Maybe DataColor
nullValueColor} -> Maybe DataColor
nullValueColor) (\s :: ColorScale
s@ColorScale' {} Maybe DataColor
a -> ColorScale
s {$sel:nullValueColor:ColorScale' :: Maybe DataColor
nullValueColor = Maybe DataColor
a} :: ColorScale)

-- | Determines the list of colors that are applied to the visual.
colorScale_colors :: Lens.Lens' ColorScale (Prelude.NonEmpty DataColor)
colorScale_colors :: Lens' ColorScale (NonEmpty DataColor)
colorScale_colors = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ColorScale' {NonEmpty DataColor
colors :: NonEmpty DataColor
$sel:colors:ColorScale' :: ColorScale -> NonEmpty DataColor
colors} -> NonEmpty DataColor
colors) (\s :: ColorScale
s@ColorScale' {} NonEmpty DataColor
a -> ColorScale
s {$sel:colors:ColorScale' :: NonEmpty DataColor
colors = NonEmpty DataColor
a} :: ColorScale) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Determines the color fill type.
colorScale_colorFillType :: Lens.Lens' ColorScale ColorFillType
colorScale_colorFillType :: Lens' ColorScale ColorFillType
colorScale_colorFillType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ColorScale' {ColorFillType
colorFillType :: ColorFillType
$sel:colorFillType:ColorScale' :: ColorScale -> ColorFillType
colorFillType} -> ColorFillType
colorFillType) (\s :: ColorScale
s@ColorScale' {} ColorFillType
a -> ColorScale
s {$sel:colorFillType:ColorScale' :: ColorFillType
colorFillType = ColorFillType
a} :: ColorScale)

instance Data.FromJSON ColorScale where
  parseJSON :: Value -> Parser ColorScale
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ColorScale"
      ( \Object
x ->
          Maybe DataColor
-> NonEmpty DataColor -> ColorFillType -> ColorScale
ColorScale'
            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
"NullValueColor")
            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
"Colors")
            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
"ColorFillType")
      )

instance Prelude.Hashable ColorScale where
  hashWithSalt :: Int -> ColorScale -> Int
hashWithSalt Int
_salt ColorScale' {Maybe DataColor
NonEmpty DataColor
ColorFillType
colorFillType :: ColorFillType
colors :: NonEmpty DataColor
nullValueColor :: Maybe DataColor
$sel:colorFillType:ColorScale' :: ColorScale -> ColorFillType
$sel:colors:ColorScale' :: ColorScale -> NonEmpty DataColor
$sel:nullValueColor:ColorScale' :: ColorScale -> Maybe DataColor
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DataColor
nullValueColor
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty DataColor
colors
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ColorFillType
colorFillType

instance Prelude.NFData ColorScale where
  rnf :: ColorScale -> ()
rnf ColorScale' {Maybe DataColor
NonEmpty DataColor
ColorFillType
colorFillType :: ColorFillType
colors :: NonEmpty DataColor
nullValueColor :: Maybe DataColor
$sel:colorFillType:ColorScale' :: ColorScale -> ColorFillType
$sel:colors:ColorScale' :: ColorScale -> NonEmpty DataColor
$sel:nullValueColor:ColorScale' :: ColorScale -> Maybe DataColor
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe DataColor
nullValueColor
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty DataColor
colors
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ColorFillType
colorFillType

instance Data.ToJSON ColorScale where
  toJSON :: ColorScale -> Value
toJSON ColorScale' {Maybe DataColor
NonEmpty DataColor
ColorFillType
colorFillType :: ColorFillType
colors :: NonEmpty DataColor
nullValueColor :: Maybe DataColor
$sel:colorFillType:ColorScale' :: ColorScale -> ColorFillType
$sel:colors:ColorScale' :: ColorScale -> NonEmpty DataColor
$sel:nullValueColor:ColorScale' :: ColorScale -> Maybe DataColor
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"NullValueColor" 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 DataColor
nullValueColor,
            forall a. a -> Maybe a
Prelude.Just (Key
"Colors" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty DataColor
colors),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ColorFillType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ColorFillType
colorFillType)
          ]
      )