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

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

-- | Describes a filter that is used to return a more specific list of
-- results from a describe operation.
--
-- If you specify multiple filters, the filters are joined with an @AND@,
-- and the request returns only results that match all of the specified
-- filters.
--
-- For more information, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-tagging.html Tagging Auto Scaling groups and instances>
-- in the /Amazon EC2 Auto Scaling User Guide/.
--
-- /See:/ 'newFilter' smart constructor.
data Filter = Filter'
  { -- | One or more filter values. Filter values are case-sensitive.
    --
    -- If you specify multiple values for a filter, the values are joined with
    -- an @OR@, and the request returns all results that match any of the
    -- specified values. For example, specify \"tag:environment\" for the
    -- filter name and \"production,development\" for the filter values to find
    -- Auto Scaling groups with the tag \"environment=production\" or
    -- \"environment=development\".
    Filter -> Maybe [Text]
values :: Prelude.Maybe [Prelude.Text],
    -- | The name of the filter.
    --
    -- The valid values for @Name@ depend on the API operation that you are
    -- including the filter in, DescribeAutoScalingGroups or DescribeTags.
    --
    -- __DescribeAutoScalingGroups__
    --
    -- Valid values for @Name@ include the following:
    --
    -- -   @tag-key@ - Accepts tag keys. The results will only include
    --     information about the Auto Scaling groups associated with these tag
    --     keys.
    --
    -- -   @tag-value@ - Accepts tag values. The results will only include
    --     information about the Auto Scaling groups associated with these tag
    --     values.
    --
    -- -   @tag:\<key>@ - Accepts the key\/value combination of the tag. Use
    --     the tag key in the filter name and the tag value as the filter
    --     value. The results will only include information about the Auto
    --     Scaling groups associated with the specified key\/value combination.
    --
    -- __DescribeTags__
    --
    -- Valid values for @Name@ include the following:
    --
    -- -   @auto-scaling-group@ - Accepts the names of Auto Scaling groups. The
    --     results will only include information about the tags associated with
    --     these Auto Scaling groups.
    --
    -- -   @key@ - Accepts tag keys. The results will only include information
    --     about the tags associated with these tag keys.
    --
    -- -   @value@ - Accepts tag values. The results will only include
    --     information about the tags associated with these tag values.
    --
    -- -   @propagate-at-launch@ - Accepts a boolean value, which specifies
    --     whether tags propagate to instances at launch. The results will only
    --     include information about the tags associated with the specified
    --     boolean value.
    Filter -> Text
name :: 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:
--
-- 'values', 'filter_values' - One or more filter values. Filter values are case-sensitive.
--
-- If you specify multiple values for a filter, the values are joined with
-- an @OR@, and the request returns all results that match any of the
-- specified values. For example, specify \"tag:environment\" for the
-- filter name and \"production,development\" for the filter values to find
-- Auto Scaling groups with the tag \"environment=production\" or
-- \"environment=development\".
--
-- 'name', 'filter_name' - The name of the filter.
--
-- The valid values for @Name@ depend on the API operation that you are
-- including the filter in, DescribeAutoScalingGroups or DescribeTags.
--
-- __DescribeAutoScalingGroups__
--
-- Valid values for @Name@ include the following:
--
-- -   @tag-key@ - Accepts tag keys. The results will only include
--     information about the Auto Scaling groups associated with these tag
--     keys.
--
-- -   @tag-value@ - Accepts tag values. The results will only include
--     information about the Auto Scaling groups associated with these tag
--     values.
--
-- -   @tag:\<key>@ - Accepts the key\/value combination of the tag. Use
--     the tag key in the filter name and the tag value as the filter
--     value. The results will only include information about the Auto
--     Scaling groups associated with the specified key\/value combination.
--
-- __DescribeTags__
--
-- Valid values for @Name@ include the following:
--
-- -   @auto-scaling-group@ - Accepts the names of Auto Scaling groups. The
--     results will only include information about the tags associated with
--     these Auto Scaling groups.
--
-- -   @key@ - Accepts tag keys. The results will only include information
--     about the tags associated with these tag keys.
--
-- -   @value@ - Accepts tag values. The results will only include
--     information about the tags associated with these tag values.
--
-- -   @propagate-at-launch@ - Accepts a boolean value, which specifies
--     whether tags propagate to instances at launch. The results will only
--     include information about the tags associated with the specified
--     boolean value.
newFilter ::
  -- | 'name'
  Prelude.Text ->
  Filter
newFilter :: Text -> Filter
newFilter Text
pName_ =
  Filter' :: Maybe [Text] -> Text -> Filter
Filter' {$sel:values:Filter' :: Maybe [Text]
values = Maybe [Text]
forall a. Maybe a
Prelude.Nothing, $sel:name:Filter' :: Text
name = Text
pName_}

-- | One or more filter values. Filter values are case-sensitive.
--
-- If you specify multiple values for a filter, the values are joined with
-- an @OR@, and the request returns all results that match any of the
-- specified values. For example, specify \"tag:environment\" for the
-- filter name and \"production,development\" for the filter values to find
-- Auto Scaling groups with the tag \"environment=production\" or
-- \"environment=development\".
filter_values :: Lens.Lens' Filter (Prelude.Maybe [Prelude.Text])
filter_values :: (Maybe [Text] -> f (Maybe [Text])) -> Filter -> f Filter
filter_values = (Filter -> Maybe [Text])
-> (Filter -> Maybe [Text] -> Filter)
-> Lens Filter Filter (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {Maybe [Text]
values :: Maybe [Text]
$sel:values:Filter' :: Filter -> Maybe [Text]
values} -> Maybe [Text]
values) (\s :: Filter
s@Filter' {} Maybe [Text]
a -> Filter
s {$sel:values:Filter' :: Maybe [Text]
values = Maybe [Text]
a} :: Filter) ((Maybe [Text] -> f (Maybe [Text])) -> Filter -> f Filter)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> Filter
-> f Filter
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

-- | The name of the filter.
--
-- The valid values for @Name@ depend on the API operation that you are
-- including the filter in, DescribeAutoScalingGroups or DescribeTags.
--
-- __DescribeAutoScalingGroups__
--
-- Valid values for @Name@ include the following:
--
-- -   @tag-key@ - Accepts tag keys. The results will only include
--     information about the Auto Scaling groups associated with these tag
--     keys.
--
-- -   @tag-value@ - Accepts tag values. The results will only include
--     information about the Auto Scaling groups associated with these tag
--     values.
--
-- -   @tag:\<key>@ - Accepts the key\/value combination of the tag. Use
--     the tag key in the filter name and the tag value as the filter
--     value. The results will only include information about the Auto
--     Scaling groups associated with the specified key\/value combination.
--
-- __DescribeTags__
--
-- Valid values for @Name@ include the following:
--
-- -   @auto-scaling-group@ - Accepts the names of Auto Scaling groups. The
--     results will only include information about the tags associated with
--     these Auto Scaling groups.
--
-- -   @key@ - Accepts tag keys. The results will only include information
--     about the tags associated with these tag keys.
--
-- -   @value@ - Accepts tag values. The results will only include
--     information about the tags associated with these tag values.
--
-- -   @propagate-at-launch@ - Accepts a boolean value, which specifies
--     whether tags propagate to instances at launch. The results will only
--     include information about the tags associated with the specified
--     boolean value.
filter_name :: Lens.Lens' Filter Prelude.Text
filter_name :: (Text -> f Text) -> Filter -> f Filter
filter_name = (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
name :: Text
$sel:name:Filter' :: Filter -> Text
name} -> Text
name) (\s :: Filter
s@Filter' {} Text
a -> Filter
s {$sel:name:Filter' :: Text
name = Text
a} :: Filter)

instance Prelude.Hashable Filter

instance Prelude.NFData Filter

instance Core.ToQuery Filter where
  toQuery :: Filter -> QueryString
toQuery Filter' {Maybe [Text]
Text
name :: Text
values :: Maybe [Text]
$sel:name:Filter' :: Filter -> Text
$sel:values:Filter' :: Filter -> Maybe [Text]
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Values"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            (ByteString -> [Text] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" ([Text] -> QueryString) -> Maybe [Text] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
values),
        ByteString
"Name" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
name
      ]