{-# 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.IoTSiteWise.Types.AssetModelHierarchy
-- 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.IoTSiteWise.Types.AssetModelHierarchy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes an asset hierarchy that contains a hierarchy\'s name, ID, and
-- child asset model ID that specifies the type of asset that can be in
-- this hierarchy.
--
-- /See:/ 'newAssetModelHierarchy' smart constructor.
data AssetModelHierarchy = AssetModelHierarchy'
  { -- | The ID of the asset model hierarchy. This ID is a @hierarchyId@.
    AssetModelHierarchy -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | The name of the asset model hierarchy that you specify by using the
    -- <https://docs.aws.amazon.com/iot-sitewise/latest/APIReference/API_CreateAssetModel.html CreateAssetModel>
    -- or
    -- <https://docs.aws.amazon.com/iot-sitewise/latest/APIReference/API_UpdateAssetModel.html UpdateAssetModel>
    -- API operation.
    AssetModelHierarchy -> Text
name :: Prelude.Text,
    -- | The ID of the asset model. All assets in this hierarchy must be
    -- instances of the @childAssetModelId@ asset model.
    AssetModelHierarchy -> Text
childAssetModelId :: Prelude.Text
  }
  deriving (AssetModelHierarchy -> AssetModelHierarchy -> Bool
(AssetModelHierarchy -> AssetModelHierarchy -> Bool)
-> (AssetModelHierarchy -> AssetModelHierarchy -> Bool)
-> Eq AssetModelHierarchy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssetModelHierarchy -> AssetModelHierarchy -> Bool
$c/= :: AssetModelHierarchy -> AssetModelHierarchy -> Bool
== :: AssetModelHierarchy -> AssetModelHierarchy -> Bool
$c== :: AssetModelHierarchy -> AssetModelHierarchy -> Bool
Prelude.Eq, ReadPrec [AssetModelHierarchy]
ReadPrec AssetModelHierarchy
Int -> ReadS AssetModelHierarchy
ReadS [AssetModelHierarchy]
(Int -> ReadS AssetModelHierarchy)
-> ReadS [AssetModelHierarchy]
-> ReadPrec AssetModelHierarchy
-> ReadPrec [AssetModelHierarchy]
-> Read AssetModelHierarchy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssetModelHierarchy]
$creadListPrec :: ReadPrec [AssetModelHierarchy]
readPrec :: ReadPrec AssetModelHierarchy
$creadPrec :: ReadPrec AssetModelHierarchy
readList :: ReadS [AssetModelHierarchy]
$creadList :: ReadS [AssetModelHierarchy]
readsPrec :: Int -> ReadS AssetModelHierarchy
$creadsPrec :: Int -> ReadS AssetModelHierarchy
Prelude.Read, Int -> AssetModelHierarchy -> ShowS
[AssetModelHierarchy] -> ShowS
AssetModelHierarchy -> String
(Int -> AssetModelHierarchy -> ShowS)
-> (AssetModelHierarchy -> String)
-> ([AssetModelHierarchy] -> ShowS)
-> Show AssetModelHierarchy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssetModelHierarchy] -> ShowS
$cshowList :: [AssetModelHierarchy] -> ShowS
show :: AssetModelHierarchy -> String
$cshow :: AssetModelHierarchy -> String
showsPrec :: Int -> AssetModelHierarchy -> ShowS
$cshowsPrec :: Int -> AssetModelHierarchy -> ShowS
Prelude.Show, (forall x. AssetModelHierarchy -> Rep AssetModelHierarchy x)
-> (forall x. Rep AssetModelHierarchy x -> AssetModelHierarchy)
-> Generic AssetModelHierarchy
forall x. Rep AssetModelHierarchy x -> AssetModelHierarchy
forall x. AssetModelHierarchy -> Rep AssetModelHierarchy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssetModelHierarchy x -> AssetModelHierarchy
$cfrom :: forall x. AssetModelHierarchy -> Rep AssetModelHierarchy x
Prelude.Generic)

-- |
-- Create a value of 'AssetModelHierarchy' 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:
--
-- 'id', 'assetModelHierarchy_id' - The ID of the asset model hierarchy. This ID is a @hierarchyId@.
--
-- 'name', 'assetModelHierarchy_name' - The name of the asset model hierarchy that you specify by using the
-- <https://docs.aws.amazon.com/iot-sitewise/latest/APIReference/API_CreateAssetModel.html CreateAssetModel>
-- or
-- <https://docs.aws.amazon.com/iot-sitewise/latest/APIReference/API_UpdateAssetModel.html UpdateAssetModel>
-- API operation.
--
-- 'childAssetModelId', 'assetModelHierarchy_childAssetModelId' - The ID of the asset model. All assets in this hierarchy must be
-- instances of the @childAssetModelId@ asset model.
newAssetModelHierarchy ::
  -- | 'name'
  Prelude.Text ->
  -- | 'childAssetModelId'
  Prelude.Text ->
  AssetModelHierarchy
newAssetModelHierarchy :: Text -> Text -> AssetModelHierarchy
newAssetModelHierarchy Text
pName_ Text
pChildAssetModelId_ =
  AssetModelHierarchy' :: Maybe Text -> Text -> Text -> AssetModelHierarchy
AssetModelHierarchy'
    { $sel:id:AssetModelHierarchy' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:AssetModelHierarchy' :: Text
name = Text
pName_,
      $sel:childAssetModelId:AssetModelHierarchy' :: Text
childAssetModelId = Text
pChildAssetModelId_
    }

-- | The ID of the asset model hierarchy. This ID is a @hierarchyId@.
assetModelHierarchy_id :: Lens.Lens' AssetModelHierarchy (Prelude.Maybe Prelude.Text)
assetModelHierarchy_id :: (Maybe Text -> f (Maybe Text))
-> AssetModelHierarchy -> f AssetModelHierarchy
assetModelHierarchy_id = (AssetModelHierarchy -> Maybe Text)
-> (AssetModelHierarchy -> Maybe Text -> AssetModelHierarchy)
-> Lens
     AssetModelHierarchy AssetModelHierarchy (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetModelHierarchy' {Maybe Text
id :: Maybe Text
$sel:id:AssetModelHierarchy' :: AssetModelHierarchy -> Maybe Text
id} -> Maybe Text
id) (\s :: AssetModelHierarchy
s@AssetModelHierarchy' {} Maybe Text
a -> AssetModelHierarchy
s {$sel:id:AssetModelHierarchy' :: Maybe Text
id = Maybe Text
a} :: AssetModelHierarchy)

-- | The name of the asset model hierarchy that you specify by using the
-- <https://docs.aws.amazon.com/iot-sitewise/latest/APIReference/API_CreateAssetModel.html CreateAssetModel>
-- or
-- <https://docs.aws.amazon.com/iot-sitewise/latest/APIReference/API_UpdateAssetModel.html UpdateAssetModel>
-- API operation.
assetModelHierarchy_name :: Lens.Lens' AssetModelHierarchy Prelude.Text
assetModelHierarchy_name :: (Text -> f Text) -> AssetModelHierarchy -> f AssetModelHierarchy
assetModelHierarchy_name = (AssetModelHierarchy -> Text)
-> (AssetModelHierarchy -> Text -> AssetModelHierarchy)
-> Lens AssetModelHierarchy AssetModelHierarchy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetModelHierarchy' {Text
name :: Text
$sel:name:AssetModelHierarchy' :: AssetModelHierarchy -> Text
name} -> Text
name) (\s :: AssetModelHierarchy
s@AssetModelHierarchy' {} Text
a -> AssetModelHierarchy
s {$sel:name:AssetModelHierarchy' :: Text
name = Text
a} :: AssetModelHierarchy)

-- | The ID of the asset model. All assets in this hierarchy must be
-- instances of the @childAssetModelId@ asset model.
assetModelHierarchy_childAssetModelId :: Lens.Lens' AssetModelHierarchy Prelude.Text
assetModelHierarchy_childAssetModelId :: (Text -> f Text) -> AssetModelHierarchy -> f AssetModelHierarchy
assetModelHierarchy_childAssetModelId = (AssetModelHierarchy -> Text)
-> (AssetModelHierarchy -> Text -> AssetModelHierarchy)
-> Lens AssetModelHierarchy AssetModelHierarchy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetModelHierarchy' {Text
childAssetModelId :: Text
$sel:childAssetModelId:AssetModelHierarchy' :: AssetModelHierarchy -> Text
childAssetModelId} -> Text
childAssetModelId) (\s :: AssetModelHierarchy
s@AssetModelHierarchy' {} Text
a -> AssetModelHierarchy
s {$sel:childAssetModelId:AssetModelHierarchy' :: Text
childAssetModelId = Text
a} :: AssetModelHierarchy)

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

instance Prelude.Hashable AssetModelHierarchy

instance Prelude.NFData AssetModelHierarchy

instance Core.ToJSON AssetModelHierarchy where
  toJSON :: AssetModelHierarchy -> Value
toJSON AssetModelHierarchy' {Maybe Text
Text
childAssetModelId :: Text
name :: Text
id :: Maybe Text
$sel:childAssetModelId:AssetModelHierarchy' :: AssetModelHierarchy -> Text
$sel:name:AssetModelHierarchy' :: AssetModelHierarchy -> Text
$sel:id:AssetModelHierarchy' :: AssetModelHierarchy -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"id" 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
id,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"childAssetModelId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
childAssetModelId)
          ]
      )