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

import qualified Amazonka.Core as Core
import Amazonka.Forecast.Types.SchemaAttribute
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Defines the fields of a dataset. You specify this object in the
-- CreateDataset request.
--
-- /See:/ 'newSchema' smart constructor.
data Schema = Schema'
  { -- | An array of attributes specifying the name and type of each field in a
    -- dataset.
    Schema -> Maybe (NonEmpty SchemaAttribute)
attributes :: Prelude.Maybe (Prelude.NonEmpty SchemaAttribute)
  }
  deriving (Schema -> Schema -> Bool
(Schema -> Schema -> Bool)
-> (Schema -> Schema -> Bool) -> Eq Schema
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Schema -> Schema -> Bool
$c/= :: Schema -> Schema -> Bool
== :: Schema -> Schema -> Bool
$c== :: Schema -> Schema -> Bool
Prelude.Eq, ReadPrec [Schema]
ReadPrec Schema
Int -> ReadS Schema
ReadS [Schema]
(Int -> ReadS Schema)
-> ReadS [Schema]
-> ReadPrec Schema
-> ReadPrec [Schema]
-> Read Schema
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Schema]
$creadListPrec :: ReadPrec [Schema]
readPrec :: ReadPrec Schema
$creadPrec :: ReadPrec Schema
readList :: ReadS [Schema]
$creadList :: ReadS [Schema]
readsPrec :: Int -> ReadS Schema
$creadsPrec :: Int -> ReadS Schema
Prelude.Read, Int -> Schema -> ShowS
[Schema] -> ShowS
Schema -> String
(Int -> Schema -> ShowS)
-> (Schema -> String) -> ([Schema] -> ShowS) -> Show Schema
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Schema] -> ShowS
$cshowList :: [Schema] -> ShowS
show :: Schema -> String
$cshow :: Schema -> String
showsPrec :: Int -> Schema -> ShowS
$cshowsPrec :: Int -> Schema -> ShowS
Prelude.Show, (forall x. Schema -> Rep Schema x)
-> (forall x. Rep Schema x -> Schema) -> Generic Schema
forall x. Rep Schema x -> Schema
forall x. Schema -> Rep Schema x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Schema x -> Schema
$cfrom :: forall x. Schema -> Rep Schema x
Prelude.Generic)

-- |
-- Create a value of 'Schema' 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:
--
-- 'attributes', 'schema_attributes' - An array of attributes specifying the name and type of each field in a
-- dataset.
newSchema ::
  Schema
newSchema :: Schema
newSchema = Schema' :: Maybe (NonEmpty SchemaAttribute) -> Schema
Schema' {$sel:attributes:Schema' :: Maybe (NonEmpty SchemaAttribute)
attributes = Maybe (NonEmpty SchemaAttribute)
forall a. Maybe a
Prelude.Nothing}

-- | An array of attributes specifying the name and type of each field in a
-- dataset.
schema_attributes :: Lens.Lens' Schema (Prelude.Maybe (Prelude.NonEmpty SchemaAttribute))
schema_attributes :: (Maybe (NonEmpty SchemaAttribute)
 -> f (Maybe (NonEmpty SchemaAttribute)))
-> Schema -> f Schema
schema_attributes = (Schema -> Maybe (NonEmpty SchemaAttribute))
-> (Schema -> Maybe (NonEmpty SchemaAttribute) -> Schema)
-> Lens
     Schema
     Schema
     (Maybe (NonEmpty SchemaAttribute))
     (Maybe (NonEmpty SchemaAttribute))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Schema' {Maybe (NonEmpty SchemaAttribute)
attributes :: Maybe (NonEmpty SchemaAttribute)
$sel:attributes:Schema' :: Schema -> Maybe (NonEmpty SchemaAttribute)
attributes} -> Maybe (NonEmpty SchemaAttribute)
attributes) (\s :: Schema
s@Schema' {} Maybe (NonEmpty SchemaAttribute)
a -> Schema
s {$sel:attributes:Schema' :: Maybe (NonEmpty SchemaAttribute)
attributes = Maybe (NonEmpty SchemaAttribute)
a} :: Schema) ((Maybe (NonEmpty SchemaAttribute)
  -> f (Maybe (NonEmpty SchemaAttribute)))
 -> Schema -> f Schema)
-> ((Maybe (NonEmpty SchemaAttribute)
     -> f (Maybe (NonEmpty SchemaAttribute)))
    -> Maybe (NonEmpty SchemaAttribute)
    -> f (Maybe (NonEmpty SchemaAttribute)))
-> (Maybe (NonEmpty SchemaAttribute)
    -> f (Maybe (NonEmpty SchemaAttribute)))
-> Schema
-> f Schema
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty SchemaAttribute)
  (NonEmpty SchemaAttribute)
  (NonEmpty SchemaAttribute)
  (NonEmpty SchemaAttribute)
-> Iso
     (Maybe (NonEmpty SchemaAttribute))
     (Maybe (NonEmpty SchemaAttribute))
     (Maybe (NonEmpty SchemaAttribute))
     (Maybe (NonEmpty SchemaAttribute))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty SchemaAttribute)
  (NonEmpty SchemaAttribute)
  (NonEmpty SchemaAttribute)
  (NonEmpty SchemaAttribute)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Schema where
  parseJSON :: Value -> Parser Schema
parseJSON =
    String -> (Object -> Parser Schema) -> Value -> Parser Schema
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Schema"
      ( \Object
x ->
          Maybe (NonEmpty SchemaAttribute) -> Schema
Schema' (Maybe (NonEmpty SchemaAttribute) -> Schema)
-> Parser (Maybe (NonEmpty SchemaAttribute)) -> Parser Schema
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty SchemaAttribute))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Attributes")
      )

instance Prelude.Hashable Schema

instance Prelude.NFData Schema

instance Core.ToJSON Schema where
  toJSON :: Schema -> Value
toJSON Schema' {Maybe (NonEmpty SchemaAttribute)
attributes :: Maybe (NonEmpty SchemaAttribute)
$sel:attributes:Schema' :: Schema -> Maybe (NonEmpty SchemaAttribute)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"Attributes" Text -> NonEmpty SchemaAttribute -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty SchemaAttribute -> Pair)
-> Maybe (NonEmpty SchemaAttribute) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty SchemaAttribute)
attributes]
      )