{-# 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.Pricing.Types.Filter
-- 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.Pricing.Types.Filter where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Pricing.Types.FilterType

-- | The constraints that you want all returned products to match.
--
-- /See:/ 'newFilter' smart constructor.
data Filter = Filter'
  { -- | The type of filter that you want to use.
    --
    -- Valid values are: @TERM_MATCH@. @TERM_MATCH@ returns only products that
    -- match both the given filter field and the given value.
    Filter -> FilterType
type' :: FilterType,
    -- | The product metadata field that you want to filter on. You can filter by
    -- just the service code to see all products for a specific service, filter
    -- by just the attribute name to see a specific attribute for multiple
    -- services, or use both a service code and an attribute name to retrieve
    -- only products that match both fields.
    --
    -- Valid values include: @ServiceCode@, and all attribute names
    --
    -- For example, you can filter by the @AmazonEC2@ service code and the
    -- @volumeType@ attribute name to get the prices for only Amazon EC2
    -- volumes.
    Filter -> Text
field :: Prelude.Text,
    -- | The service code or attribute value that you want to filter by. If you
    -- are filtering by service code this is the actual service code, such as
    -- @AmazonEC2@. If you are filtering by attribute name, this is the
    -- attribute value that you want the returned products to match, such as a
    -- @Provisioned IOPS@ volume.
    Filter -> Text
value :: Prelude.Text
  }
  deriving (Filter -> Filter -> Bool
(Filter -> Filter -> Bool)
-> (Filter -> Filter -> Bool) -> Eq Filter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Filter -> Filter -> Bool
$c/= :: Filter -> Filter -> Bool
== :: Filter -> Filter -> Bool
$c== :: Filter -> Filter -> Bool
Prelude.Eq, ReadPrec [Filter]
ReadPrec Filter
Int -> ReadS Filter
ReadS [Filter]
(Int -> ReadS Filter)
-> ReadS [Filter]
-> ReadPrec Filter
-> ReadPrec [Filter]
-> Read Filter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Filter]
$creadListPrec :: ReadPrec [Filter]
readPrec :: ReadPrec Filter
$creadPrec :: ReadPrec Filter
readList :: ReadS [Filter]
$creadList :: ReadS [Filter]
readsPrec :: Int -> ReadS Filter
$creadsPrec :: Int -> ReadS Filter
Prelude.Read, Int -> Filter -> ShowS
[Filter] -> ShowS
Filter -> String
(Int -> Filter -> ShowS)
-> (Filter -> String) -> ([Filter] -> ShowS) -> Show Filter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Filter] -> ShowS
$cshowList :: [Filter] -> ShowS
show :: Filter -> String
$cshow :: Filter -> String
showsPrec :: Int -> Filter -> ShowS
$cshowsPrec :: Int -> Filter -> ShowS
Prelude.Show, (forall x. Filter -> Rep Filter x)
-> (forall x. Rep Filter x -> Filter) -> Generic Filter
forall x. Rep Filter x -> Filter
forall x. Filter -> Rep Filter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Filter x -> Filter
$cfrom :: forall x. Filter -> Rep Filter x
Prelude.Generic)

-- |
-- Create a value of 'Filter' 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:
--
-- 'type'', 'filter_type' - The type of filter that you want to use.
--
-- Valid values are: @TERM_MATCH@. @TERM_MATCH@ returns only products that
-- match both the given filter field and the given value.
--
-- 'field', 'filter_field' - The product metadata field that you want to filter on. You can filter by
-- just the service code to see all products for a specific service, filter
-- by just the attribute name to see a specific attribute for multiple
-- services, or use both a service code and an attribute name to retrieve
-- only products that match both fields.
--
-- Valid values include: @ServiceCode@, and all attribute names
--
-- For example, you can filter by the @AmazonEC2@ service code and the
-- @volumeType@ attribute name to get the prices for only Amazon EC2
-- volumes.
--
-- 'value', 'filter_value' - The service code or attribute value that you want to filter by. If you
-- are filtering by service code this is the actual service code, such as
-- @AmazonEC2@. If you are filtering by attribute name, this is the
-- attribute value that you want the returned products to match, such as a
-- @Provisioned IOPS@ volume.
newFilter ::
  -- | 'type''
  FilterType ->
  -- | 'field'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  Filter
newFilter :: FilterType -> Text -> Text -> Filter
newFilter FilterType
pType_ Text
pField_ Text
pValue_ =
  Filter' :: FilterType -> Text -> Text -> Filter
Filter'
    { $sel:type':Filter' :: FilterType
type' = FilterType
pType_,
      $sel:field:Filter' :: Text
field = Text
pField_,
      $sel:value:Filter' :: Text
value = Text
pValue_
    }

-- | The type of filter that you want to use.
--
-- Valid values are: @TERM_MATCH@. @TERM_MATCH@ returns only products that
-- match both the given filter field and the given value.
filter_type :: Lens.Lens' Filter FilterType
filter_type :: (FilterType -> f FilterType) -> Filter -> f Filter
filter_type = (Filter -> FilterType)
-> (Filter -> FilterType -> Filter)
-> Lens Filter Filter FilterType FilterType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {FilterType
type' :: FilterType
$sel:type':Filter' :: Filter -> FilterType
type'} -> FilterType
type') (\s :: Filter
s@Filter' {} FilterType
a -> Filter
s {$sel:type':Filter' :: FilterType
type' = FilterType
a} :: Filter)

-- | The product metadata field that you want to filter on. You can filter by
-- just the service code to see all products for a specific service, filter
-- by just the attribute name to see a specific attribute for multiple
-- services, or use both a service code and an attribute name to retrieve
-- only products that match both fields.
--
-- Valid values include: @ServiceCode@, and all attribute names
--
-- For example, you can filter by the @AmazonEC2@ service code and the
-- @volumeType@ attribute name to get the prices for only Amazon EC2
-- volumes.
filter_field :: Lens.Lens' Filter Prelude.Text
filter_field :: (Text -> f Text) -> Filter -> f Filter
filter_field = (Filter -> Text)
-> (Filter -> Text -> Filter) -> Lens Filter Filter Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {Text
field :: Text
$sel:field:Filter' :: Filter -> Text
field} -> Text
field) (\s :: Filter
s@Filter' {} Text
a -> Filter
s {$sel:field:Filter' :: Text
field = Text
a} :: Filter)

-- | The service code or attribute value that you want to filter by. If you
-- are filtering by service code this is the actual service code, such as
-- @AmazonEC2@. If you are filtering by attribute name, this is the
-- attribute value that you want the returned products to match, such as a
-- @Provisioned IOPS@ volume.
filter_value :: Lens.Lens' Filter Prelude.Text
filter_value :: (Text -> f Text) -> Filter -> f Filter
filter_value = (Filter -> Text)
-> (Filter -> Text -> Filter) -> Lens Filter Filter Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {Text
value :: Text
$sel:value:Filter' :: Filter -> Text
value} -> Text
value) (\s :: Filter
s@Filter' {} Text
a -> Filter
s {$sel:value:Filter' :: Text
value = Text
a} :: Filter)

instance Prelude.Hashable Filter

instance Prelude.NFData Filter

instance Core.ToJSON Filter where
  toJSON :: Filter -> Value
toJSON Filter' {Text
FilterType
value :: Text
field :: Text
type' :: FilterType
$sel:value:Filter' :: Filter -> Text
$sel:field:Filter' :: Filter -> Text
$sel:type':Filter' :: Filter -> FilterType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> FilterType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= FilterType
type'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Field" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
field),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
value)
          ]
      )