{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Greengrass.Types.Core where

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

-- | 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
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]
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
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. 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'
    { $sel:syncShadow:Core' :: Maybe Bool
syncShadow = 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 :: Lens' Core (Maybe Bool)
core_syncShadow = 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 :: Lens' Core Text
core_thingArn = 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 :: Lens' Core Text
core_id = 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 :: Lens' Core Text
core_certificateArn = 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 Data.FromJSON Core where
  parseJSON :: Value -> Parser Core
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Core"
      ( \Object
x ->
          Maybe Bool -> Text -> Text -> Text -> Core
Core'
            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
"SyncShadow")
            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
"ThingArn")
            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
"Id")
            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
"CertificateArn")
      )

instance Prelude.Hashable Core where
  hashWithSalt :: Int -> Core -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
syncShadow
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
thingArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
certificateArn

instance Prelude.NFData Core where
  rnf :: Core -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
syncShadow
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
thingArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
id
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
certificateArn

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"SyncShadow" 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 Bool
syncShadow,
            forall a. a -> Maybe a
Prelude.Just (Key
"ThingArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
thingArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"Id" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
id),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"CertificateArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
certificateArn)
          ]
      )