{-# 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.MarketplaceCatalog.Types.Entity
-- 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.MarketplaceCatalog.Types.Entity where

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

-- | An entity contains data that describes your product, its supported
-- features, and how it can be used or launched by your customer.
--
-- /See:/ 'newEntity' smart constructor.
data Entity = Entity'
  { -- | The identifier for the entity.
    Entity -> Maybe Text
identifier :: Prelude.Maybe Prelude.Text,
    -- | The type of entity.
    Entity -> Text
type' :: Prelude.Text
  }
  deriving (Entity -> Entity -> Bool
(Entity -> Entity -> Bool)
-> (Entity -> Entity -> Bool) -> Eq Entity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Entity -> Entity -> Bool
$c/= :: Entity -> Entity -> Bool
== :: Entity -> Entity -> Bool
$c== :: Entity -> Entity -> Bool
Prelude.Eq, ReadPrec [Entity]
ReadPrec Entity
Int -> ReadS Entity
ReadS [Entity]
(Int -> ReadS Entity)
-> ReadS [Entity]
-> ReadPrec Entity
-> ReadPrec [Entity]
-> Read Entity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Entity]
$creadListPrec :: ReadPrec [Entity]
readPrec :: ReadPrec Entity
$creadPrec :: ReadPrec Entity
readList :: ReadS [Entity]
$creadList :: ReadS [Entity]
readsPrec :: Int -> ReadS Entity
$creadsPrec :: Int -> ReadS Entity
Prelude.Read, Int -> Entity -> ShowS
[Entity] -> ShowS
Entity -> String
(Int -> Entity -> ShowS)
-> (Entity -> String) -> ([Entity] -> ShowS) -> Show Entity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Entity] -> ShowS
$cshowList :: [Entity] -> ShowS
show :: Entity -> String
$cshow :: Entity -> String
showsPrec :: Int -> Entity -> ShowS
$cshowsPrec :: Int -> Entity -> ShowS
Prelude.Show, (forall x. Entity -> Rep Entity x)
-> (forall x. Rep Entity x -> Entity) -> Generic Entity
forall x. Rep Entity x -> Entity
forall x. Entity -> Rep Entity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Entity x -> Entity
$cfrom :: forall x. Entity -> Rep Entity x
Prelude.Generic)

-- |
-- Create a value of 'Entity' 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:
--
-- 'identifier', 'entity_identifier' - The identifier for the entity.
--
-- 'type'', 'entity_type' - The type of entity.
newEntity ::
  -- | 'type''
  Prelude.Text ->
  Entity
newEntity :: Text -> Entity
newEntity Text
pType_ =
  Entity' :: Maybe Text -> Text -> Entity
Entity'
    { $sel:identifier:Entity' :: Maybe Text
identifier = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:type':Entity' :: Text
type' = Text
pType_
    }

-- | The identifier for the entity.
entity_identifier :: Lens.Lens' Entity (Prelude.Maybe Prelude.Text)
entity_identifier :: (Maybe Text -> f (Maybe Text)) -> Entity -> f Entity
entity_identifier = (Entity -> Maybe Text)
-> (Entity -> Maybe Text -> Entity)
-> Lens Entity Entity (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Maybe Text
identifier :: Maybe Text
$sel:identifier:Entity' :: Entity -> Maybe Text
identifier} -> Maybe Text
identifier) (\s :: Entity
s@Entity' {} Maybe Text
a -> Entity
s {$sel:identifier:Entity' :: Maybe Text
identifier = Maybe Text
a} :: Entity)

-- | The type of entity.
entity_type :: Lens.Lens' Entity Prelude.Text
entity_type :: (Text -> f Text) -> Entity -> f Entity
entity_type = (Entity -> Text)
-> (Entity -> Text -> Entity) -> Lens Entity Entity Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Text
type' :: Text
$sel:type':Entity' :: Entity -> Text
type'} -> Text
type') (\s :: Entity
s@Entity' {} Text
a -> Entity
s {$sel:type':Entity' :: Text
type' = Text
a} :: Entity)

instance Core.FromJSON Entity where
  parseJSON :: Value -> Parser Entity
parseJSON =
    String -> (Object -> Parser Entity) -> Value -> Parser Entity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Entity"
      ( \Object
x ->
          Maybe Text -> Text -> Entity
Entity'
            (Maybe Text -> Text -> Entity)
-> Parser (Maybe Text) -> Parser (Text -> Entity)
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
"Identifier")
            Parser (Text -> Entity) -> Parser Text -> Parser Entity
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
"Type")
      )

instance Prelude.Hashable Entity

instance Prelude.NFData Entity

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