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

import qualified Amazonka.Core as Core
import Amazonka.Forecast.Types.AttributeType
import qualified Amazonka.Lens as Lens
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 Schema object
-- contains an array of @SchemaAttribute@ objects.
--
-- /See:/ 'newSchemaAttribute' smart constructor.
data SchemaAttribute = SchemaAttribute'
  { -- | The data type of the field.
    SchemaAttribute -> Maybe AttributeType
attributeType :: Prelude.Maybe AttributeType,
    -- | The name of the dataset field.
    SchemaAttribute -> Maybe Text
attributeName :: Prelude.Maybe Prelude.Text
  }
  deriving (SchemaAttribute -> SchemaAttribute -> Bool
(SchemaAttribute -> SchemaAttribute -> Bool)
-> (SchemaAttribute -> SchemaAttribute -> Bool)
-> Eq SchemaAttribute
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]
(Int -> ReadS SchemaAttribute)
-> ReadS [SchemaAttribute]
-> ReadPrec SchemaAttribute
-> ReadPrec [SchemaAttribute]
-> Read 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
(Int -> SchemaAttribute -> ShowS)
-> (SchemaAttribute -> String)
-> ([SchemaAttribute] -> ShowS)
-> Show SchemaAttribute
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. SchemaAttribute -> Rep SchemaAttribute x)
-> (forall x. Rep SchemaAttribute x -> SchemaAttribute)
-> Generic SchemaAttribute
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:
--
-- 'attributeType', 'schemaAttribute_attributeType' - The data type of the field.
--
-- 'attributeName', 'schemaAttribute_attributeName' - The name of the dataset field.
newSchemaAttribute ::
  SchemaAttribute
newSchemaAttribute :: SchemaAttribute
newSchemaAttribute =
  SchemaAttribute' :: Maybe AttributeType -> Maybe Text -> SchemaAttribute
SchemaAttribute'
    { $sel:attributeType:SchemaAttribute' :: Maybe AttributeType
attributeType = Maybe AttributeType
forall a. Maybe a
Prelude.Nothing,
      $sel:attributeName:SchemaAttribute' :: Maybe Text
attributeName = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The data type of the field.
schemaAttribute_attributeType :: Lens.Lens' SchemaAttribute (Prelude.Maybe AttributeType)
schemaAttribute_attributeType :: (Maybe AttributeType -> f (Maybe AttributeType))
-> SchemaAttribute -> f SchemaAttribute
schemaAttribute_attributeType = (SchemaAttribute -> Maybe AttributeType)
-> (SchemaAttribute -> Maybe AttributeType -> SchemaAttribute)
-> Lens
     SchemaAttribute
     SchemaAttribute
     (Maybe AttributeType)
     (Maybe 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)

-- | The name of the dataset field.
schemaAttribute_attributeName :: Lens.Lens' SchemaAttribute (Prelude.Maybe Prelude.Text)
schemaAttribute_attributeName :: (Maybe Text -> f (Maybe Text))
-> SchemaAttribute -> f SchemaAttribute
schemaAttribute_attributeName = (SchemaAttribute -> Maybe Text)
-> (SchemaAttribute -> Maybe Text -> SchemaAttribute)
-> Lens SchemaAttribute SchemaAttribute (Maybe Text) (Maybe Text)
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)

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

instance Prelude.Hashable SchemaAttribute

instance Prelude.NFData SchemaAttribute

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