{-# 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.AmplifyUiBuilder.Types.ComponentDataConfiguration
-- 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.AmplifyUiBuilder.Types.ComponentDataConfiguration where

import Amazonka.AmplifyUiBuilder.Types.Predicate
import Amazonka.AmplifyUiBuilder.Types.SortProperty
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

-- | Describes the configuration for binding a component\'s properties to
-- data.
--
-- /See:/ 'newComponentDataConfiguration' smart constructor.
data ComponentDataConfiguration = ComponentDataConfiguration'
  { -- | A list of IDs to use to bind data to a component. Use this property to
    -- bind specifically chosen data, rather than data retrieved from a query.
    ComponentDataConfiguration -> Maybe [Text]
identifiers :: Prelude.Maybe [Prelude.Text],
    -- | Represents the conditional logic to use when binding data to a
    -- component. Use this property to retrieve only a subset of the data in a
    -- collection.
    ComponentDataConfiguration -> Maybe Predicate
predicate :: Prelude.Maybe Predicate,
    -- | Describes how to sort the component\'s properties.
    ComponentDataConfiguration -> Maybe [SortProperty]
sort :: Prelude.Maybe [SortProperty],
    -- | The name of the data model to use to bind data to a component.
    ComponentDataConfiguration -> Text
model :: Prelude.Text
  }
  deriving (ComponentDataConfiguration -> ComponentDataConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ComponentDataConfiguration -> ComponentDataConfiguration -> Bool
$c/= :: ComponentDataConfiguration -> ComponentDataConfiguration -> Bool
== :: ComponentDataConfiguration -> ComponentDataConfiguration -> Bool
$c== :: ComponentDataConfiguration -> ComponentDataConfiguration -> Bool
Prelude.Eq, ReadPrec [ComponentDataConfiguration]
ReadPrec ComponentDataConfiguration
Int -> ReadS ComponentDataConfiguration
ReadS [ComponentDataConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ComponentDataConfiguration]
$creadListPrec :: ReadPrec [ComponentDataConfiguration]
readPrec :: ReadPrec ComponentDataConfiguration
$creadPrec :: ReadPrec ComponentDataConfiguration
readList :: ReadS [ComponentDataConfiguration]
$creadList :: ReadS [ComponentDataConfiguration]
readsPrec :: Int -> ReadS ComponentDataConfiguration
$creadsPrec :: Int -> ReadS ComponentDataConfiguration
Prelude.Read, Int -> ComponentDataConfiguration -> ShowS
[ComponentDataConfiguration] -> ShowS
ComponentDataConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ComponentDataConfiguration] -> ShowS
$cshowList :: [ComponentDataConfiguration] -> ShowS
show :: ComponentDataConfiguration -> String
$cshow :: ComponentDataConfiguration -> String
showsPrec :: Int -> ComponentDataConfiguration -> ShowS
$cshowsPrec :: Int -> ComponentDataConfiguration -> ShowS
Prelude.Show, forall x.
Rep ComponentDataConfiguration x -> ComponentDataConfiguration
forall x.
ComponentDataConfiguration -> Rep ComponentDataConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ComponentDataConfiguration x -> ComponentDataConfiguration
$cfrom :: forall x.
ComponentDataConfiguration -> Rep ComponentDataConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ComponentDataConfiguration' 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:
--
-- 'identifiers', 'componentDataConfiguration_identifiers' - A list of IDs to use to bind data to a component. Use this property to
-- bind specifically chosen data, rather than data retrieved from a query.
--
-- 'predicate', 'componentDataConfiguration_predicate' - Represents the conditional logic to use when binding data to a
-- component. Use this property to retrieve only a subset of the data in a
-- collection.
--
-- 'sort', 'componentDataConfiguration_sort' - Describes how to sort the component\'s properties.
--
-- 'model', 'componentDataConfiguration_model' - The name of the data model to use to bind data to a component.
newComponentDataConfiguration ::
  -- | 'model'
  Prelude.Text ->
  ComponentDataConfiguration
newComponentDataConfiguration :: Text -> ComponentDataConfiguration
newComponentDataConfiguration Text
pModel_ =
  ComponentDataConfiguration'
    { $sel:identifiers:ComponentDataConfiguration' :: Maybe [Text]
identifiers =
        forall a. Maybe a
Prelude.Nothing,
      $sel:predicate:ComponentDataConfiguration' :: Maybe Predicate
predicate = forall a. Maybe a
Prelude.Nothing,
      $sel:sort:ComponentDataConfiguration' :: Maybe [SortProperty]
sort = forall a. Maybe a
Prelude.Nothing,
      $sel:model:ComponentDataConfiguration' :: Text
model = Text
pModel_
    }

-- | A list of IDs to use to bind data to a component. Use this property to
-- bind specifically chosen data, rather than data retrieved from a query.
componentDataConfiguration_identifiers :: Lens.Lens' ComponentDataConfiguration (Prelude.Maybe [Prelude.Text])
componentDataConfiguration_identifiers :: Lens' ComponentDataConfiguration (Maybe [Text])
componentDataConfiguration_identifiers = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentDataConfiguration' {Maybe [Text]
identifiers :: Maybe [Text]
$sel:identifiers:ComponentDataConfiguration' :: ComponentDataConfiguration -> Maybe [Text]
identifiers} -> Maybe [Text]
identifiers) (\s :: ComponentDataConfiguration
s@ComponentDataConfiguration' {} Maybe [Text]
a -> ComponentDataConfiguration
s {$sel:identifiers:ComponentDataConfiguration' :: Maybe [Text]
identifiers = Maybe [Text]
a} :: ComponentDataConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Represents the conditional logic to use when binding data to a
-- component. Use this property to retrieve only a subset of the data in a
-- collection.
componentDataConfiguration_predicate :: Lens.Lens' ComponentDataConfiguration (Prelude.Maybe Predicate)
componentDataConfiguration_predicate :: Lens' ComponentDataConfiguration (Maybe Predicate)
componentDataConfiguration_predicate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentDataConfiguration' {Maybe Predicate
predicate :: Maybe Predicate
$sel:predicate:ComponentDataConfiguration' :: ComponentDataConfiguration -> Maybe Predicate
predicate} -> Maybe Predicate
predicate) (\s :: ComponentDataConfiguration
s@ComponentDataConfiguration' {} Maybe Predicate
a -> ComponentDataConfiguration
s {$sel:predicate:ComponentDataConfiguration' :: Maybe Predicate
predicate = Maybe Predicate
a} :: ComponentDataConfiguration)

-- | Describes how to sort the component\'s properties.
componentDataConfiguration_sort :: Lens.Lens' ComponentDataConfiguration (Prelude.Maybe [SortProperty])
componentDataConfiguration_sort :: Lens' ComponentDataConfiguration (Maybe [SortProperty])
componentDataConfiguration_sort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentDataConfiguration' {Maybe [SortProperty]
sort :: Maybe [SortProperty]
$sel:sort:ComponentDataConfiguration' :: ComponentDataConfiguration -> Maybe [SortProperty]
sort} -> Maybe [SortProperty]
sort) (\s :: ComponentDataConfiguration
s@ComponentDataConfiguration' {} Maybe [SortProperty]
a -> ComponentDataConfiguration
s {$sel:sort:ComponentDataConfiguration' :: Maybe [SortProperty]
sort = Maybe [SortProperty]
a} :: ComponentDataConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the data model to use to bind data to a component.
componentDataConfiguration_model :: Lens.Lens' ComponentDataConfiguration Prelude.Text
componentDataConfiguration_model :: Lens' ComponentDataConfiguration Text
componentDataConfiguration_model = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentDataConfiguration' {Text
model :: Text
$sel:model:ComponentDataConfiguration' :: ComponentDataConfiguration -> Text
model} -> Text
model) (\s :: ComponentDataConfiguration
s@ComponentDataConfiguration' {} Text
a -> ComponentDataConfiguration
s {$sel:model:ComponentDataConfiguration' :: Text
model = Text
a} :: ComponentDataConfiguration)

instance Data.FromJSON ComponentDataConfiguration where
  parseJSON :: Value -> Parser ComponentDataConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ComponentDataConfiguration"
      ( \Object
x ->
          Maybe [Text]
-> Maybe Predicate
-> Maybe [SortProperty]
-> Text
-> ComponentDataConfiguration
ComponentDataConfiguration'
            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
"identifiers" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"predicate")
            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
"sort" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"model")
      )

instance Prelude.Hashable ComponentDataConfiguration where
  hashWithSalt :: Int -> ComponentDataConfiguration -> Int
hashWithSalt Int
_salt ComponentDataConfiguration' {Maybe [Text]
Maybe [SortProperty]
Maybe Predicate
Text
model :: Text
sort :: Maybe [SortProperty]
predicate :: Maybe Predicate
identifiers :: Maybe [Text]
$sel:model:ComponentDataConfiguration' :: ComponentDataConfiguration -> Text
$sel:sort:ComponentDataConfiguration' :: ComponentDataConfiguration -> Maybe [SortProperty]
$sel:predicate:ComponentDataConfiguration' :: ComponentDataConfiguration -> Maybe Predicate
$sel:identifiers:ComponentDataConfiguration' :: ComponentDataConfiguration -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
identifiers
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Predicate
predicate
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [SortProperty]
sort
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
model

instance Prelude.NFData ComponentDataConfiguration where
  rnf :: ComponentDataConfiguration -> ()
rnf ComponentDataConfiguration' {Maybe [Text]
Maybe [SortProperty]
Maybe Predicate
Text
model :: Text
sort :: Maybe [SortProperty]
predicate :: Maybe Predicate
identifiers :: Maybe [Text]
$sel:model:ComponentDataConfiguration' :: ComponentDataConfiguration -> Text
$sel:sort:ComponentDataConfiguration' :: ComponentDataConfiguration -> Maybe [SortProperty]
$sel:predicate:ComponentDataConfiguration' :: ComponentDataConfiguration -> Maybe Predicate
$sel:identifiers:ComponentDataConfiguration' :: ComponentDataConfiguration -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
identifiers
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Predicate
predicate
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [SortProperty]
sort
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
model

instance Data.ToJSON ComponentDataConfiguration where
  toJSON :: ComponentDataConfiguration -> Value
toJSON ComponentDataConfiguration' {Maybe [Text]
Maybe [SortProperty]
Maybe Predicate
Text
model :: Text
sort :: Maybe [SortProperty]
predicate :: Maybe Predicate
identifiers :: Maybe [Text]
$sel:model:ComponentDataConfiguration' :: ComponentDataConfiguration -> Text
$sel:sort:ComponentDataConfiguration' :: ComponentDataConfiguration -> Maybe [SortProperty]
$sel:predicate:ComponentDataConfiguration' :: ComponentDataConfiguration -> Maybe Predicate
$sel:identifiers:ComponentDataConfiguration' :: ComponentDataConfiguration -> Maybe [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"identifiers" 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]
identifiers,
            (Key
"predicate" 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 Predicate
predicate,
            (Key
"sort" 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 [SortProperty]
sort,
            forall a. a -> Maybe a
Prelude.Just (Key
"model" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
model)
          ]
      )