{-# 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.ECS.Types.Resource
-- 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.ECS.Types.Resource where

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

-- | Describes the resources available for a container instance.
--
-- /See:/ 'newResource' smart constructor.
data Resource = Resource'
  { -- | When the @stringSetValue@ type is set, the value of the resource must be
    -- a string type.
    Resource -> Maybe [Text]
stringSetValue :: Prelude.Maybe [Prelude.Text],
    -- | When the @integerValue@ type is set, the value of the resource must be
    -- an integer.
    Resource -> Maybe Int
integerValue :: Prelude.Maybe Prelude.Int,
    -- | When the @doubleValue@ type is set, the value of the resource must be a
    -- double precision floating-point type.
    Resource -> Maybe Double
doubleValue :: Prelude.Maybe Prelude.Double,
    -- | When the @longValue@ type is set, the value of the resource must be an
    -- extended precision floating-point type.
    Resource -> Maybe Integer
longValue :: Prelude.Maybe Prelude.Integer,
    -- | The name of the resource, such as @CPU@, @MEMORY@, @PORTS@, @PORTS_UDP@,
    -- or a user-defined resource.
    Resource -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The type of the resource, such as @INTEGER@, @DOUBLE@, @LONG@, or
    -- @STRINGSET@.
    Resource -> Maybe Text
type' :: Prelude.Maybe Prelude.Text
  }
  deriving (Resource -> Resource -> Bool
(Resource -> Resource -> Bool)
-> (Resource -> Resource -> Bool) -> Eq Resource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Resource -> Resource -> Bool
$c/= :: Resource -> Resource -> Bool
== :: Resource -> Resource -> Bool
$c== :: Resource -> Resource -> Bool
Prelude.Eq, ReadPrec [Resource]
ReadPrec Resource
Int -> ReadS Resource
ReadS [Resource]
(Int -> ReadS Resource)
-> ReadS [Resource]
-> ReadPrec Resource
-> ReadPrec [Resource]
-> Read Resource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Resource]
$creadListPrec :: ReadPrec [Resource]
readPrec :: ReadPrec Resource
$creadPrec :: ReadPrec Resource
readList :: ReadS [Resource]
$creadList :: ReadS [Resource]
readsPrec :: Int -> ReadS Resource
$creadsPrec :: Int -> ReadS Resource
Prelude.Read, Int -> Resource -> ShowS
[Resource] -> ShowS
Resource -> String
(Int -> Resource -> ShowS)
-> (Resource -> String) -> ([Resource] -> ShowS) -> Show Resource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Resource] -> ShowS
$cshowList :: [Resource] -> ShowS
show :: Resource -> String
$cshow :: Resource -> String
showsPrec :: Int -> Resource -> ShowS
$cshowsPrec :: Int -> Resource -> ShowS
Prelude.Show, (forall x. Resource -> Rep Resource x)
-> (forall x. Rep Resource x -> Resource) -> Generic Resource
forall x. Rep Resource x -> Resource
forall x. Resource -> Rep Resource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Resource x -> Resource
$cfrom :: forall x. Resource -> Rep Resource x
Prelude.Generic)

-- |
-- Create a value of 'Resource' 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:
--
-- 'stringSetValue', 'resource_stringSetValue' - When the @stringSetValue@ type is set, the value of the resource must be
-- a string type.
--
-- 'integerValue', 'resource_integerValue' - When the @integerValue@ type is set, the value of the resource must be
-- an integer.
--
-- 'doubleValue', 'resource_doubleValue' - When the @doubleValue@ type is set, the value of the resource must be a
-- double precision floating-point type.
--
-- 'longValue', 'resource_longValue' - When the @longValue@ type is set, the value of the resource must be an
-- extended precision floating-point type.
--
-- 'name', 'resource_name' - The name of the resource, such as @CPU@, @MEMORY@, @PORTS@, @PORTS_UDP@,
-- or a user-defined resource.
--
-- 'type'', 'resource_type' - The type of the resource, such as @INTEGER@, @DOUBLE@, @LONG@, or
-- @STRINGSET@.
newResource ::
  Resource
newResource :: Resource
newResource =
  Resource' :: Maybe [Text]
-> Maybe Int
-> Maybe Double
-> Maybe Integer
-> Maybe Text
-> Maybe Text
-> Resource
Resource'
    { $sel:stringSetValue:Resource' :: Maybe [Text]
stringSetValue = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:integerValue:Resource' :: Maybe Int
integerValue = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:doubleValue:Resource' :: Maybe Double
doubleValue = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:longValue:Resource' :: Maybe Integer
longValue = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Resource' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:type':Resource' :: Maybe Text
type' = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | When the @stringSetValue@ type is set, the value of the resource must be
-- a string type.
resource_stringSetValue :: Lens.Lens' Resource (Prelude.Maybe [Prelude.Text])
resource_stringSetValue :: (Maybe [Text] -> f (Maybe [Text])) -> Resource -> f Resource
resource_stringSetValue = (Resource -> Maybe [Text])
-> (Resource -> Maybe [Text] -> Resource)
-> Lens Resource Resource (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Maybe [Text]
stringSetValue :: Maybe [Text]
$sel:stringSetValue:Resource' :: Resource -> Maybe [Text]
stringSetValue} -> Maybe [Text]
stringSetValue) (\s :: Resource
s@Resource' {} Maybe [Text]
a -> Resource
s {$sel:stringSetValue:Resource' :: Maybe [Text]
stringSetValue = Maybe [Text]
a} :: Resource) ((Maybe [Text] -> f (Maybe [Text])) -> Resource -> f Resource)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> Resource
-> f Resource
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | When the @integerValue@ type is set, the value of the resource must be
-- an integer.
resource_integerValue :: Lens.Lens' Resource (Prelude.Maybe Prelude.Int)
resource_integerValue :: (Maybe Int -> f (Maybe Int)) -> Resource -> f Resource
resource_integerValue = (Resource -> Maybe Int)
-> (Resource -> Maybe Int -> Resource)
-> Lens Resource Resource (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Maybe Int
integerValue :: Maybe Int
$sel:integerValue:Resource' :: Resource -> Maybe Int
integerValue} -> Maybe Int
integerValue) (\s :: Resource
s@Resource' {} Maybe Int
a -> Resource
s {$sel:integerValue:Resource' :: Maybe Int
integerValue = Maybe Int
a} :: Resource)

-- | When the @doubleValue@ type is set, the value of the resource must be a
-- double precision floating-point type.
resource_doubleValue :: Lens.Lens' Resource (Prelude.Maybe Prelude.Double)
resource_doubleValue :: (Maybe Double -> f (Maybe Double)) -> Resource -> f Resource
resource_doubleValue = (Resource -> Maybe Double)
-> (Resource -> Maybe Double -> Resource)
-> Lens Resource Resource (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Maybe Double
doubleValue :: Maybe Double
$sel:doubleValue:Resource' :: Resource -> Maybe Double
doubleValue} -> Maybe Double
doubleValue) (\s :: Resource
s@Resource' {} Maybe Double
a -> Resource
s {$sel:doubleValue:Resource' :: Maybe Double
doubleValue = Maybe Double
a} :: Resource)

-- | When the @longValue@ type is set, the value of the resource must be an
-- extended precision floating-point type.
resource_longValue :: Lens.Lens' Resource (Prelude.Maybe Prelude.Integer)
resource_longValue :: (Maybe Integer -> f (Maybe Integer)) -> Resource -> f Resource
resource_longValue = (Resource -> Maybe Integer)
-> (Resource -> Maybe Integer -> Resource)
-> Lens Resource Resource (Maybe Integer) (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Maybe Integer
longValue :: Maybe Integer
$sel:longValue:Resource' :: Resource -> Maybe Integer
longValue} -> Maybe Integer
longValue) (\s :: Resource
s@Resource' {} Maybe Integer
a -> Resource
s {$sel:longValue:Resource' :: Maybe Integer
longValue = Maybe Integer
a} :: Resource)

-- | The name of the resource, such as @CPU@, @MEMORY@, @PORTS@, @PORTS_UDP@,
-- or a user-defined resource.
resource_name :: Lens.Lens' Resource (Prelude.Maybe Prelude.Text)
resource_name :: (Maybe Text -> f (Maybe Text)) -> Resource -> f Resource
resource_name = (Resource -> Maybe Text)
-> (Resource -> Maybe Text -> Resource)
-> Lens Resource Resource (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Maybe Text
name :: Maybe Text
$sel:name:Resource' :: Resource -> Maybe Text
name} -> Maybe Text
name) (\s :: Resource
s@Resource' {} Maybe Text
a -> Resource
s {$sel:name:Resource' :: Maybe Text
name = Maybe Text
a} :: Resource)

-- | The type of the resource, such as @INTEGER@, @DOUBLE@, @LONG@, or
-- @STRINGSET@.
resource_type :: Lens.Lens' Resource (Prelude.Maybe Prelude.Text)
resource_type :: (Maybe Text -> f (Maybe Text)) -> Resource -> f Resource
resource_type = (Resource -> Maybe Text)
-> (Resource -> Maybe Text -> Resource)
-> Lens Resource Resource (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Maybe Text
type' :: Maybe Text
$sel:type':Resource' :: Resource -> Maybe Text
type'} -> Maybe Text
type') (\s :: Resource
s@Resource' {} Maybe Text
a -> Resource
s {$sel:type':Resource' :: Maybe Text
type' = Maybe Text
a} :: Resource)

instance Core.FromJSON Resource where
  parseJSON :: Value -> Parser Resource
parseJSON =
    String -> (Object -> Parser Resource) -> Value -> Parser Resource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Resource"
      ( \Object
x ->
          Maybe [Text]
-> Maybe Int
-> Maybe Double
-> Maybe Integer
-> Maybe Text
-> Maybe Text
-> Resource
Resource'
            (Maybe [Text]
 -> Maybe Int
 -> Maybe Double
 -> Maybe Integer
 -> Maybe Text
 -> Maybe Text
 -> Resource)
-> Parser (Maybe [Text])
-> Parser
     (Maybe Int
      -> Maybe Double
      -> Maybe Integer
      -> Maybe Text
      -> Maybe Text
      -> Resource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"stringSetValue" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe Int
   -> Maybe Double
   -> Maybe Integer
   -> Maybe Text
   -> Maybe Text
   -> Resource)
-> Parser (Maybe Int)
-> Parser
     (Maybe Double
      -> Maybe Integer -> Maybe Text -> Maybe Text -> Resource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"integerValue")
            Parser
  (Maybe Double
   -> Maybe Integer -> Maybe Text -> Maybe Text -> Resource)
-> Parser (Maybe Double)
-> Parser (Maybe Integer -> Maybe Text -> Maybe Text -> Resource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"doubleValue")
            Parser (Maybe Integer -> Maybe Text -> Maybe Text -> Resource)
-> Parser (Maybe Integer)
-> Parser (Maybe Text -> Maybe Text -> Resource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"longValue")
            Parser (Maybe Text -> Maybe Text -> Resource)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Resource)
forall (f :: * -> *) a b. Applicative f => 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
"name")
            Parser (Maybe Text -> Resource)
-> Parser (Maybe Text) -> Parser Resource
forall (f :: * -> *) a b. Applicative f => 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
"type")
      )

instance Prelude.Hashable Resource

instance Prelude.NFData Resource

instance Core.ToJSON Resource where
  toJSON :: Resource -> Value
toJSON Resource' {Maybe Double
Maybe Int
Maybe Integer
Maybe [Text]
Maybe Text
type' :: Maybe Text
name :: Maybe Text
longValue :: Maybe Integer
doubleValue :: Maybe Double
integerValue :: Maybe Int
stringSetValue :: Maybe [Text]
$sel:type':Resource' :: Resource -> Maybe Text
$sel:name:Resource' :: Resource -> Maybe Text
$sel:longValue:Resource' :: Resource -> Maybe Integer
$sel:doubleValue:Resource' :: Resource -> Maybe Double
$sel:integerValue:Resource' :: Resource -> Maybe Int
$sel:stringSetValue:Resource' :: Resource -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"stringSetValue" 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]
stringSetValue,
            (Text
"integerValue" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
integerValue,
            (Text
"doubleValue" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
doubleValue,
            (Text
"longValue" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
longValue,
            (Text
"name" 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
name,
            (Text
"type" 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
type'
          ]
      )