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

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

-- | Information about a core definition version.
--
-- /See:/ 'newCoreDefinitionVersion' smart constructor.
data CoreDefinitionVersion = CoreDefinitionVersion'
  { -- | A list of cores in the core definition version.
    CoreDefinitionVersion -> Maybe [Core]
cores :: Prelude.Maybe [Core]
  }
  deriving (CoreDefinitionVersion -> CoreDefinitionVersion -> Bool
(CoreDefinitionVersion -> CoreDefinitionVersion -> Bool)
-> (CoreDefinitionVersion -> CoreDefinitionVersion -> Bool)
-> Eq CoreDefinitionVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoreDefinitionVersion -> CoreDefinitionVersion -> Bool
$c/= :: CoreDefinitionVersion -> CoreDefinitionVersion -> Bool
== :: CoreDefinitionVersion -> CoreDefinitionVersion -> Bool
$c== :: CoreDefinitionVersion -> CoreDefinitionVersion -> Bool
Prelude.Eq, ReadPrec [CoreDefinitionVersion]
ReadPrec CoreDefinitionVersion
Int -> ReadS CoreDefinitionVersion
ReadS [CoreDefinitionVersion]
(Int -> ReadS CoreDefinitionVersion)
-> ReadS [CoreDefinitionVersion]
-> ReadPrec CoreDefinitionVersion
-> ReadPrec [CoreDefinitionVersion]
-> Read CoreDefinitionVersion
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CoreDefinitionVersion]
$creadListPrec :: ReadPrec [CoreDefinitionVersion]
readPrec :: ReadPrec CoreDefinitionVersion
$creadPrec :: ReadPrec CoreDefinitionVersion
readList :: ReadS [CoreDefinitionVersion]
$creadList :: ReadS [CoreDefinitionVersion]
readsPrec :: Int -> ReadS CoreDefinitionVersion
$creadsPrec :: Int -> ReadS CoreDefinitionVersion
Prelude.Read, Int -> CoreDefinitionVersion -> ShowS
[CoreDefinitionVersion] -> ShowS
CoreDefinitionVersion -> String
(Int -> CoreDefinitionVersion -> ShowS)
-> (CoreDefinitionVersion -> String)
-> ([CoreDefinitionVersion] -> ShowS)
-> Show CoreDefinitionVersion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoreDefinitionVersion] -> ShowS
$cshowList :: [CoreDefinitionVersion] -> ShowS
show :: CoreDefinitionVersion -> String
$cshow :: CoreDefinitionVersion -> String
showsPrec :: Int -> CoreDefinitionVersion -> ShowS
$cshowsPrec :: Int -> CoreDefinitionVersion -> ShowS
Prelude.Show, (forall x. CoreDefinitionVersion -> Rep CoreDefinitionVersion x)
-> (forall x. Rep CoreDefinitionVersion x -> CoreDefinitionVersion)
-> Generic CoreDefinitionVersion
forall x. Rep CoreDefinitionVersion x -> CoreDefinitionVersion
forall x. CoreDefinitionVersion -> Rep CoreDefinitionVersion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CoreDefinitionVersion x -> CoreDefinitionVersion
$cfrom :: forall x. CoreDefinitionVersion -> Rep CoreDefinitionVersion x
Prelude.Generic)

-- |
-- Create a value of 'CoreDefinitionVersion' 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:
--
-- 'cores', 'coreDefinitionVersion_cores' - A list of cores in the core definition version.
newCoreDefinitionVersion ::
  CoreDefinitionVersion
newCoreDefinitionVersion :: CoreDefinitionVersion
newCoreDefinitionVersion =
  CoreDefinitionVersion' :: Maybe [Core] -> CoreDefinitionVersion
CoreDefinitionVersion' {$sel:cores:CoreDefinitionVersion' :: Maybe [Core]
cores = Maybe [Core]
forall a. Maybe a
Prelude.Nothing}

-- | A list of cores in the core definition version.
coreDefinitionVersion_cores :: Lens.Lens' CoreDefinitionVersion (Prelude.Maybe [Core])
coreDefinitionVersion_cores :: (Maybe [Core] -> f (Maybe [Core]))
-> CoreDefinitionVersion -> f CoreDefinitionVersion
coreDefinitionVersion_cores = (CoreDefinitionVersion -> Maybe [Core])
-> (CoreDefinitionVersion -> Maybe [Core] -> CoreDefinitionVersion)
-> Lens
     CoreDefinitionVersion
     CoreDefinitionVersion
     (Maybe [Core])
     (Maybe [Core])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CoreDefinitionVersion' {Maybe [Core]
cores :: Maybe [Core]
$sel:cores:CoreDefinitionVersion' :: CoreDefinitionVersion -> Maybe [Core]
cores} -> Maybe [Core]
cores) (\s :: CoreDefinitionVersion
s@CoreDefinitionVersion' {} Maybe [Core]
a -> CoreDefinitionVersion
s {$sel:cores:CoreDefinitionVersion' :: Maybe [Core]
cores = Maybe [Core]
a} :: CoreDefinitionVersion) ((Maybe [Core] -> f (Maybe [Core]))
 -> CoreDefinitionVersion -> f CoreDefinitionVersion)
-> ((Maybe [Core] -> f (Maybe [Core]))
    -> Maybe [Core] -> f (Maybe [Core]))
-> (Maybe [Core] -> f (Maybe [Core]))
-> CoreDefinitionVersion
-> f CoreDefinitionVersion
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Core] [Core] [Core] [Core]
-> Iso (Maybe [Core]) (Maybe [Core]) (Maybe [Core]) (Maybe [Core])
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 AnIso [Core] [Core] [Core] [Core]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON CoreDefinitionVersion where
  parseJSON :: Value -> Parser CoreDefinitionVersion
parseJSON =
    String
-> (Object -> Parser CoreDefinitionVersion)
-> Value
-> Parser CoreDefinitionVersion
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CoreDefinitionVersion"
      ( \Object
x ->
          Maybe [Core] -> CoreDefinitionVersion
CoreDefinitionVersion'
            (Maybe [Core] -> CoreDefinitionVersion)
-> Parser (Maybe [Core]) -> Parser CoreDefinitionVersion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Core]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Cores" Parser (Maybe (Maybe [Core]))
-> Maybe [Core] -> Parser (Maybe [Core])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Core]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable CoreDefinitionVersion

instance Prelude.NFData CoreDefinitionVersion

instance Core.ToJSON CoreDefinitionVersion where
  toJSON :: CoreDefinitionVersion -> Value
toJSON CoreDefinitionVersion' {Maybe [Core]
cores :: Maybe [Core]
$sel:cores:CoreDefinitionVersion' :: CoreDefinitionVersion -> Maybe [Core]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"Cores" Text -> [Core] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Core] -> Pair) -> Maybe [Core] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Core]
cores]
      )