{-# 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.Greengrass.Types.Core
-- 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.Greengrass.Types.Core where

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

-- | Information about a core.
--
-- /See:/ 'newCore' smart constructor.
data Core = Core'
  { -- | If true, the core\'s local shadow is automatically synced with the
    -- cloud.
    Core -> Maybe Bool
syncShadow :: Prelude.Maybe Prelude.Bool,
    -- | The ARN of the thing which is the core.
    Core -> Text
thingArn :: Prelude.Text,
    -- | A descriptive or arbitrary ID for the core. This value must be unique
    -- within the core definition version. Max length is 128 characters with
    -- pattern \'\'[a-zA-Z0-9:_-]+\'\'.
    Core -> Text
id :: Prelude.Text,
    -- | The ARN of the certificate associated with the core.
    Core -> Text
certificateArn :: Prelude.Text
  }
  deriving (Core -> Core -> Bool
(Core -> Core -> Bool) -> (Core -> Core -> Bool) -> Eq Core
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Core -> Core -> Bool
$c/= :: Core -> Core -> Bool
== :: Core -> Core -> Bool
$c== :: Core -> Core -> Bool
Prelude.Eq, ReadPrec [Core]
ReadPrec Core
Int -> ReadS Core
ReadS [Core]
(Int -> ReadS Core)
-> ReadS [Core] -> ReadPrec Core -> ReadPrec [Core] -> Read Core
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Core]
$creadListPrec :: ReadPrec [Core]
readPrec :: ReadPrec Core
$creadPrec :: ReadPrec Core
readList :: ReadS [Core]
$creadList :: ReadS [Core]
readsPrec :: Int -> ReadS Core
$creadsPrec :: Int -> ReadS Core
Prelude.Read, Int -> Core -> ShowS
[Core] -> ShowS
Core -> String
(Int -> Core -> ShowS)
-> (Core -> String) -> ([Core] -> ShowS) -> Show Core
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Core] -> ShowS
$cshowList :: [Core] -> ShowS
show :: Core -> String
$cshow :: Core -> String
showsPrec :: Int -> Core -> ShowS
$cshowsPrec :: Int -> Core -> ShowS
Prelude.Show, (forall x. Core -> Rep Core x)
-> (forall x. Rep Core x -> Core) -> Generic Core
forall x. Rep Core x -> Core
forall x. Core -> Rep Core x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Core x -> Core
$cfrom :: forall x. Core -> Rep Core x
Prelude.Generic)

-- |
-- Create a value of 'Core' 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:
--
-- 'syncShadow', 'core_syncShadow' - If true, the core\'s local shadow is automatically synced with the
-- cloud.
--
-- 'thingArn', 'core_thingArn' - The ARN of the thing which is the core.
--
-- 'id', 'core_id' - A descriptive or arbitrary ID for the core. This value must be unique
-- within the core definition version. Max length is 128 characters with
-- pattern \'\'[a-zA-Z0-9:_-]+\'\'.
--
-- 'certificateArn', 'core_certificateArn' - The ARN of the certificate associated with the core.
newCore ::
  -- | 'thingArn'
  Prelude.Text ->
  -- | 'id'
  Prelude.Text ->
  -- | 'certificateArn'
  Prelude.Text ->
  Core
newCore :: Text -> Text -> Text -> Core
newCore Text
pThingArn_ Text
pId_ Text
pCertificateArn_ =
  Core' :: Maybe Bool -> Text -> Text -> Text -> Core
Core'
    { $sel:syncShadow:Core' :: Maybe Bool
syncShadow = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:thingArn:Core' :: Text
thingArn = Text
pThingArn_,
      $sel:id:Core' :: Text
id = Text
pId_,
      $sel:certificateArn:Core' :: Text
certificateArn = Text
pCertificateArn_
    }

-- | If true, the core\'s local shadow is automatically synced with the
-- cloud.
core_syncShadow :: Lens.Lens' Core (Prelude.Maybe Prelude.Bool)
core_syncShadow :: (Maybe Bool -> f (Maybe Bool)) -> Core -> f Core
core_syncShadow = (Core -> Maybe Bool)
-> (Core -> Maybe Bool -> Core)
-> Lens Core Core (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Core' {Maybe Bool
syncShadow :: Maybe Bool
$sel:syncShadow:Core' :: Core -> Maybe Bool
syncShadow} -> Maybe Bool
syncShadow) (\s :: Core
s@Core' {} Maybe Bool
a -> Core
s {$sel:syncShadow:Core' :: Maybe Bool
syncShadow = Maybe Bool
a} :: Core)

-- | The ARN of the thing which is the core.
core_thingArn :: Lens.Lens' Core Prelude.Text
core_thingArn :: (Text -> f Text) -> Core -> f Core
core_thingArn = (Core -> Text)
-> (Core -> Text -> Core) -> Lens Core Core Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Core' {Text
thingArn :: Text
$sel:thingArn:Core' :: Core -> Text
thingArn} -> Text
thingArn) (\s :: Core
s@Core' {} Text
a -> Core
s {$sel:thingArn:Core' :: Text
thingArn = Text
a} :: Core)

-- | A descriptive or arbitrary ID for the core. This value must be unique
-- within the core definition version. Max length is 128 characters with
-- pattern \'\'[a-zA-Z0-9:_-]+\'\'.
core_id :: Lens.Lens' Core Prelude.Text
core_id :: (Text -> f Text) -> Core -> f Core
core_id = (Core -> Text)
-> (Core -> Text -> Core) -> Lens Core Core Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Core' {Text
id :: Text
$sel:id:Core' :: Core -> Text
id} -> Text
id) (\s :: Core
s@Core' {} Text
a -> Core
s {$sel:id:Core' :: Text
id = Text
a} :: Core)

-- | The ARN of the certificate associated with the core.
core_certificateArn :: Lens.Lens' Core Prelude.Text
core_certificateArn :: (Text -> f Text) -> Core -> f Core
core_certificateArn = (Core -> Text)
-> (Core -> Text -> Core) -> Lens Core Core Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Core' {Text
certificateArn :: Text
$sel:certificateArn:Core' :: Core -> Text
certificateArn} -> Text
certificateArn) (\s :: Core
s@Core' {} Text
a -> Core
s {$sel:certificateArn:Core' :: Text
certificateArn = Text
a} :: Core)

instance Core.FromJSON Core where
  parseJSON :: Value -> Parser Core
parseJSON =
    String -> (Object -> Parser Core) -> Value -> Parser Core
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Core"
      ( \Object
x ->
          Maybe Bool -> Text -> Text -> Text -> Core
Core'
            (Maybe Bool -> Text -> Text -> Text -> Core)
-> Parser (Maybe Bool) -> Parser (Text -> Text -> Text -> Core)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SyncShadow")
            Parser (Text -> Text -> Text -> Core)
-> Parser Text -> Parser (Text -> Text -> Core)
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
"ThingArn")
            Parser (Text -> Text -> Core)
-> Parser Text -> Parser (Text -> Core)
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
"Id")
            Parser (Text -> Core) -> Parser Text -> Parser Core
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
"CertificateArn")
      )

instance Prelude.Hashable Core

instance Prelude.NFData Core

instance Core.ToJSON Core where
  toJSON :: Core -> Value
toJSON Core' {Maybe Bool
Text
certificateArn :: Text
id :: Text
thingArn :: Text
syncShadow :: Maybe Bool
$sel:certificateArn:Core' :: Core -> Text
$sel:id:Core' :: Core -> Text
$sel:thingArn:Core' :: Core -> Text
$sel:syncShadow:Core' :: Core -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"SyncShadow" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
syncShadow,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ThingArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
thingArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"CertificateArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
certificateArn)
          ]
      )