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

import Amazonka.AmplifyUiBuilder.Types.ComponentEvent
import Amazonka.AmplifyUiBuilder.Types.ComponentProperty
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

-- | A nested UI configuration within a parent @Component@.
--
-- /See:/ 'newComponentChild' smart constructor.
data ComponentChild = ComponentChild'
  { -- | The list of @ComponentChild@ instances for this component.
    ComponentChild -> Maybe [ComponentChild]
children :: Prelude.Maybe [ComponentChild],
    -- | Describes the events that can be raised on the child component. Use for
    -- the workflow feature in Amplify Studio that allows you to bind events
    -- and actions to components.
    ComponentChild -> Maybe (HashMap Text ComponentEvent)
events :: Prelude.Maybe (Prelude.HashMap Prelude.Text ComponentEvent),
    -- | The unique ID of the child component in its original source system, such
    -- as Figma.
    ComponentChild -> Maybe Text
sourceId :: Prelude.Maybe Prelude.Text,
    -- | The type of the child component.
    ComponentChild -> Text
componentType :: Prelude.Text,
    -- | The name of the child component.
    ComponentChild -> Text
name :: Prelude.Text,
    -- | Describes the properties of the child component. You can\'t specify
    -- @tags@ as a valid property for @properties@.
    ComponentChild -> HashMap Text ComponentProperty
properties :: Prelude.HashMap Prelude.Text ComponentProperty
  }
  deriving (ComponentChild -> ComponentChild -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ComponentChild -> ComponentChild -> Bool
$c/= :: ComponentChild -> ComponentChild -> Bool
== :: ComponentChild -> ComponentChild -> Bool
$c== :: ComponentChild -> ComponentChild -> Bool
Prelude.Eq, ReadPrec [ComponentChild]
ReadPrec ComponentChild
Int -> ReadS ComponentChild
ReadS [ComponentChild]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ComponentChild]
$creadListPrec :: ReadPrec [ComponentChild]
readPrec :: ReadPrec ComponentChild
$creadPrec :: ReadPrec ComponentChild
readList :: ReadS [ComponentChild]
$creadList :: ReadS [ComponentChild]
readsPrec :: Int -> ReadS ComponentChild
$creadsPrec :: Int -> ReadS ComponentChild
Prelude.Read, Int -> ComponentChild -> ShowS
[ComponentChild] -> ShowS
ComponentChild -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ComponentChild] -> ShowS
$cshowList :: [ComponentChild] -> ShowS
show :: ComponentChild -> String
$cshow :: ComponentChild -> String
showsPrec :: Int -> ComponentChild -> ShowS
$cshowsPrec :: Int -> ComponentChild -> ShowS
Prelude.Show, forall x. Rep ComponentChild x -> ComponentChild
forall x. ComponentChild -> Rep ComponentChild x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ComponentChild x -> ComponentChild
$cfrom :: forall x. ComponentChild -> Rep ComponentChild x
Prelude.Generic)

-- |
-- Create a value of 'ComponentChild' 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:
--
-- 'children', 'componentChild_children' - The list of @ComponentChild@ instances for this component.
--
-- 'events', 'componentChild_events' - Describes the events that can be raised on the child component. Use for
-- the workflow feature in Amplify Studio that allows you to bind events
-- and actions to components.
--
-- 'sourceId', 'componentChild_sourceId' - The unique ID of the child component in its original source system, such
-- as Figma.
--
-- 'componentType', 'componentChild_componentType' - The type of the child component.
--
-- 'name', 'componentChild_name' - The name of the child component.
--
-- 'properties', 'componentChild_properties' - Describes the properties of the child component. You can\'t specify
-- @tags@ as a valid property for @properties@.
newComponentChild ::
  -- | 'componentType'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  ComponentChild
newComponentChild :: Text -> Text -> ComponentChild
newComponentChild Text
pComponentType_ Text
pName_ =
  ComponentChild'
    { $sel:children:ComponentChild' :: Maybe [ComponentChild]
children = forall a. Maybe a
Prelude.Nothing,
      $sel:events:ComponentChild' :: Maybe (HashMap Text ComponentEvent)
events = forall a. Maybe a
Prelude.Nothing,
      $sel:sourceId:ComponentChild' :: Maybe Text
sourceId = forall a. Maybe a
Prelude.Nothing,
      $sel:componentType:ComponentChild' :: Text
componentType = Text
pComponentType_,
      $sel:name:ComponentChild' :: Text
name = Text
pName_,
      $sel:properties:ComponentChild' :: HashMap Text ComponentProperty
properties = forall a. Monoid a => a
Prelude.mempty
    }

-- | The list of @ComponentChild@ instances for this component.
componentChild_children :: Lens.Lens' ComponentChild (Prelude.Maybe [ComponentChild])
componentChild_children :: Lens' ComponentChild (Maybe [ComponentChild])
componentChild_children = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentChild' {Maybe [ComponentChild]
children :: Maybe [ComponentChild]
$sel:children:ComponentChild' :: ComponentChild -> Maybe [ComponentChild]
children} -> Maybe [ComponentChild]
children) (\s :: ComponentChild
s@ComponentChild' {} Maybe [ComponentChild]
a -> ComponentChild
s {$sel:children:ComponentChild' :: Maybe [ComponentChild]
children = Maybe [ComponentChild]
a} :: ComponentChild) 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

-- | Describes the events that can be raised on the child component. Use for
-- the workflow feature in Amplify Studio that allows you to bind events
-- and actions to components.
componentChild_events :: Lens.Lens' ComponentChild (Prelude.Maybe (Prelude.HashMap Prelude.Text ComponentEvent))
componentChild_events :: Lens' ComponentChild (Maybe (HashMap Text ComponentEvent))
componentChild_events = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentChild' {Maybe (HashMap Text ComponentEvent)
events :: Maybe (HashMap Text ComponentEvent)
$sel:events:ComponentChild' :: ComponentChild -> Maybe (HashMap Text ComponentEvent)
events} -> Maybe (HashMap Text ComponentEvent)
events) (\s :: ComponentChild
s@ComponentChild' {} Maybe (HashMap Text ComponentEvent)
a -> ComponentChild
s {$sel:events:ComponentChild' :: Maybe (HashMap Text ComponentEvent)
events = Maybe (HashMap Text ComponentEvent)
a} :: ComponentChild) 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 unique ID of the child component in its original source system, such
-- as Figma.
componentChild_sourceId :: Lens.Lens' ComponentChild (Prelude.Maybe Prelude.Text)
componentChild_sourceId :: Lens' ComponentChild (Maybe Text)
componentChild_sourceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentChild' {Maybe Text
sourceId :: Maybe Text
$sel:sourceId:ComponentChild' :: ComponentChild -> Maybe Text
sourceId} -> Maybe Text
sourceId) (\s :: ComponentChild
s@ComponentChild' {} Maybe Text
a -> ComponentChild
s {$sel:sourceId:ComponentChild' :: Maybe Text
sourceId = Maybe Text
a} :: ComponentChild)

-- | The type of the child component.
componentChild_componentType :: Lens.Lens' ComponentChild Prelude.Text
componentChild_componentType :: Lens' ComponentChild Text
componentChild_componentType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentChild' {Text
componentType :: Text
$sel:componentType:ComponentChild' :: ComponentChild -> Text
componentType} -> Text
componentType) (\s :: ComponentChild
s@ComponentChild' {} Text
a -> ComponentChild
s {$sel:componentType:ComponentChild' :: Text
componentType = Text
a} :: ComponentChild)

-- | The name of the child component.
componentChild_name :: Lens.Lens' ComponentChild Prelude.Text
componentChild_name :: Lens' ComponentChild Text
componentChild_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentChild' {Text
name :: Text
$sel:name:ComponentChild' :: ComponentChild -> Text
name} -> Text
name) (\s :: ComponentChild
s@ComponentChild' {} Text
a -> ComponentChild
s {$sel:name:ComponentChild' :: Text
name = Text
a} :: ComponentChild)

-- | Describes the properties of the child component. You can\'t specify
-- @tags@ as a valid property for @properties@.
componentChild_properties :: Lens.Lens' ComponentChild (Prelude.HashMap Prelude.Text ComponentProperty)
componentChild_properties :: Lens' ComponentChild (HashMap Text ComponentProperty)
componentChild_properties = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentChild' {HashMap Text ComponentProperty
properties :: HashMap Text ComponentProperty
$sel:properties:ComponentChild' :: ComponentChild -> HashMap Text ComponentProperty
properties} -> HashMap Text ComponentProperty
properties) (\s :: ComponentChild
s@ComponentChild' {} HashMap Text ComponentProperty
a -> ComponentChild
s {$sel:properties:ComponentChild' :: HashMap Text ComponentProperty
properties = HashMap Text ComponentProperty
a} :: ComponentChild) 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

instance Data.FromJSON ComponentChild where
  parseJSON :: Value -> Parser ComponentChild
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ComponentChild"
      ( \Object
x ->
          Maybe [ComponentChild]
-> Maybe (HashMap Text ComponentEvent)
-> Maybe Text
-> Text
-> Text
-> HashMap Text ComponentProperty
-> ComponentChild
ComponentChild'
            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
"children" 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
"events" 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
"sourceId")
            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
"componentType")
            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
"name")
            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
"properties" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ComponentChild where
  hashWithSalt :: Int -> ComponentChild -> Int
hashWithSalt Int
_salt ComponentChild' {Maybe [ComponentChild]
Maybe Text
Maybe (HashMap Text ComponentEvent)
Text
HashMap Text ComponentProperty
properties :: HashMap Text ComponentProperty
name :: Text
componentType :: Text
sourceId :: Maybe Text
events :: Maybe (HashMap Text ComponentEvent)
children :: Maybe [ComponentChild]
$sel:properties:ComponentChild' :: ComponentChild -> HashMap Text ComponentProperty
$sel:name:ComponentChild' :: ComponentChild -> Text
$sel:componentType:ComponentChild' :: ComponentChild -> Text
$sel:sourceId:ComponentChild' :: ComponentChild -> Maybe Text
$sel:events:ComponentChild' :: ComponentChild -> Maybe (HashMap Text ComponentEvent)
$sel:children:ComponentChild' :: ComponentChild -> Maybe [ComponentChild]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [ComponentChild]
children
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text ComponentEvent)
events
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sourceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
componentType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` HashMap Text ComponentProperty
properties

instance Prelude.NFData ComponentChild where
  rnf :: ComponentChild -> ()
rnf ComponentChild' {Maybe [ComponentChild]
Maybe Text
Maybe (HashMap Text ComponentEvent)
Text
HashMap Text ComponentProperty
properties :: HashMap Text ComponentProperty
name :: Text
componentType :: Text
sourceId :: Maybe Text
events :: Maybe (HashMap Text ComponentEvent)
children :: Maybe [ComponentChild]
$sel:properties:ComponentChild' :: ComponentChild -> HashMap Text ComponentProperty
$sel:name:ComponentChild' :: ComponentChild -> Text
$sel:componentType:ComponentChild' :: ComponentChild -> Text
$sel:sourceId:ComponentChild' :: ComponentChild -> Maybe Text
$sel:events:ComponentChild' :: ComponentChild -> Maybe (HashMap Text ComponentEvent)
$sel:children:ComponentChild' :: ComponentChild -> Maybe [ComponentChild]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [ComponentChild]
children
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text ComponentEvent)
events
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
sourceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
componentType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf HashMap Text ComponentProperty
properties

instance Data.ToJSON ComponentChild where
  toJSON :: ComponentChild -> Value
toJSON ComponentChild' {Maybe [ComponentChild]
Maybe Text
Maybe (HashMap Text ComponentEvent)
Text
HashMap Text ComponentProperty
properties :: HashMap Text ComponentProperty
name :: Text
componentType :: Text
sourceId :: Maybe Text
events :: Maybe (HashMap Text ComponentEvent)
children :: Maybe [ComponentChild]
$sel:properties:ComponentChild' :: ComponentChild -> HashMap Text ComponentProperty
$sel:name:ComponentChild' :: ComponentChild -> Text
$sel:componentType:ComponentChild' :: ComponentChild -> Text
$sel:sourceId:ComponentChild' :: ComponentChild -> Maybe Text
$sel:events:ComponentChild' :: ComponentChild -> Maybe (HashMap Text ComponentEvent)
$sel:children:ComponentChild' :: ComponentChild -> Maybe [ComponentChild]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"children" 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 [ComponentChild]
children,
            (Key
"events" 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 (HashMap Text ComponentEvent)
events,
            (Key
"sourceId" 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
sourceId,
            forall a. a -> Maybe a
Prelude.Just (Key
"componentType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
componentType),
            forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"properties" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= HashMap Text ComponentProperty
properties)
          ]
      )