{-# 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.Forecast.Types.SchemaAttribute
-- 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.Forecast.Types.SchemaAttribute where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Forecast.Types.AttributeType
import qualified Amazonka.Prelude as Prelude

-- | An attribute of a schema, which defines a dataset field. A schema
-- attribute is required for every field in a dataset. The
-- <https://docs.aws.amazon.com/forecast/latest/dg/API_Schema.html Schema>
-- object contains an array of @SchemaAttribute@ objects.
--
-- /See:/ 'newSchemaAttribute' smart constructor.
data SchemaAttribute = SchemaAttribute'
  { -- | The name of the dataset field.
    SchemaAttribute -> Maybe Text
attributeName :: Prelude.Maybe Prelude.Text,
    -- | The data type of the field.
    --
    -- For a related time series dataset, other than date, item_id, and
    -- forecast dimensions attributes, all attributes should be of numerical
    -- type (integer\/float).
    SchemaAttribute -> Maybe AttributeType
attributeType :: Prelude.Maybe AttributeType
  }
  deriving (SchemaAttribute -> SchemaAttribute -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SchemaAttribute -> SchemaAttribute -> Bool
$c/= :: SchemaAttribute -> SchemaAttribute -> Bool
== :: SchemaAttribute -> SchemaAttribute -> Bool
$c== :: SchemaAttribute -> SchemaAttribute -> Bool
Prelude.Eq, ReadPrec [SchemaAttribute]
ReadPrec SchemaAttribute
Int -> ReadS SchemaAttribute
ReadS [SchemaAttribute]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SchemaAttribute]
$creadListPrec :: ReadPrec [SchemaAttribute]
readPrec :: ReadPrec SchemaAttribute
$creadPrec :: ReadPrec SchemaAttribute
readList :: ReadS [SchemaAttribute]
$creadList :: ReadS [SchemaAttribute]
readsPrec :: Int -> ReadS SchemaAttribute
$creadsPrec :: Int -> ReadS SchemaAttribute
Prelude.Read, Int -> SchemaAttribute -> ShowS
[SchemaAttribute] -> ShowS
SchemaAttribute -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SchemaAttribute] -> ShowS
$cshowList :: [SchemaAttribute] -> ShowS
show :: SchemaAttribute -> String
$cshow :: SchemaAttribute -> String
showsPrec :: Int -> SchemaAttribute -> ShowS
$cshowsPrec :: Int -> SchemaAttribute -> ShowS
Prelude.Show, forall x. Rep SchemaAttribute x -> SchemaAttribute
forall x. SchemaAttribute -> Rep SchemaAttribute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SchemaAttribute x -> SchemaAttribute
$cfrom :: forall x. SchemaAttribute -> Rep SchemaAttribute x
Prelude.Generic)

-- |
-- Create a value of 'SchemaAttribute' 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:
--
-- 'attributeName', 'schemaAttribute_attributeName' - The name of the dataset field.
--
-- 'attributeType', 'schemaAttribute_attributeType' - The data type of the field.
--
-- For a related time series dataset, other than date, item_id, and
-- forecast dimensions attributes, all attributes should be of numerical
-- type (integer\/float).
newSchemaAttribute ::
  SchemaAttribute
newSchemaAttribute :: SchemaAttribute
newSchemaAttribute =
  SchemaAttribute'
    { $sel:attributeName:SchemaAttribute' :: Maybe Text
attributeName = forall a. Maybe a
Prelude.Nothing,
      $sel:attributeType:SchemaAttribute' :: Maybe AttributeType
attributeType = forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the dataset field.
schemaAttribute_attributeName :: Lens.Lens' SchemaAttribute (Prelude.Maybe Prelude.Text)
schemaAttribute_attributeName :: Lens' SchemaAttribute (Maybe Text)
schemaAttribute_attributeName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SchemaAttribute' {Maybe Text
attributeName :: Maybe Text
$sel:attributeName:SchemaAttribute' :: SchemaAttribute -> Maybe Text
attributeName} -> Maybe Text
attributeName) (\s :: SchemaAttribute
s@SchemaAttribute' {} Maybe Text
a -> SchemaAttribute
s {$sel:attributeName:SchemaAttribute' :: Maybe Text
attributeName = Maybe Text
a} :: SchemaAttribute)

-- | The data type of the field.
--
-- For a related time series dataset, other than date, item_id, and
-- forecast dimensions attributes, all attributes should be of numerical
-- type (integer\/float).
schemaAttribute_attributeType :: Lens.Lens' SchemaAttribute (Prelude.Maybe AttributeType)
schemaAttribute_attributeType :: Lens' SchemaAttribute (Maybe AttributeType)
schemaAttribute_attributeType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SchemaAttribute' {Maybe AttributeType
attributeType :: Maybe AttributeType
$sel:attributeType:SchemaAttribute' :: SchemaAttribute -> Maybe AttributeType
attributeType} -> Maybe AttributeType
attributeType) (\s :: SchemaAttribute
s@SchemaAttribute' {} Maybe AttributeType
a -> SchemaAttribute
s {$sel:attributeType:SchemaAttribute' :: Maybe AttributeType
attributeType = Maybe AttributeType
a} :: SchemaAttribute)

instance Data.FromJSON SchemaAttribute where
  parseJSON :: Value -> Parser SchemaAttribute
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SchemaAttribute"
      ( \Object
x ->
          Maybe Text -> Maybe AttributeType -> SchemaAttribute
SchemaAttribute'
            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
"AttributeName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"AttributeType")
      )

instance Prelude.Hashable SchemaAttribute where
  hashWithSalt :: Int -> SchemaAttribute -> Int
hashWithSalt Int
_salt SchemaAttribute' {Maybe Text
Maybe AttributeType
attributeType :: Maybe AttributeType
attributeName :: Maybe Text
$sel:attributeType:SchemaAttribute' :: SchemaAttribute -> Maybe AttributeType
$sel:attributeName:SchemaAttribute' :: SchemaAttribute -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
attributeName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AttributeType
attributeType

instance Prelude.NFData SchemaAttribute where
  rnf :: SchemaAttribute -> ()
rnf SchemaAttribute' {Maybe Text
Maybe AttributeType
attributeType :: Maybe AttributeType
attributeName :: Maybe Text
$sel:attributeType:SchemaAttribute' :: SchemaAttribute -> Maybe AttributeType
$sel:attributeName:SchemaAttribute' :: SchemaAttribute -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
attributeName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe AttributeType
attributeType

instance Data.ToJSON SchemaAttribute where
  toJSON :: SchemaAttribute -> Value
toJSON SchemaAttribute' {Maybe Text
Maybe AttributeType
attributeType :: Maybe AttributeType
attributeName :: Maybe Text
$sel:attributeType:SchemaAttribute' :: SchemaAttribute -> Maybe AttributeType
$sel:attributeName:SchemaAttribute' :: SchemaAttribute -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AttributeName" 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
attributeName,
            (Key
"AttributeType" 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 AttributeType
attributeType
          ]
      )