{-# 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.CloudWatchLogs.Types.QueryDefinition
-- 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.CloudWatchLogs.Types.QueryDefinition where

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

-- | This structure contains details about a saved CloudWatch Logs Insights
-- query definition.
--
-- /See:/ 'newQueryDefinition' smart constructor.
data QueryDefinition = QueryDefinition'
  { -- | If this query definition contains a list of log groups that it is
    -- limited to, that list appears here.
    QueryDefinition -> Maybe [Text]
logGroupNames :: Prelude.Maybe [Prelude.Text],
    -- | The unique ID of the query definition.
    QueryDefinition -> Maybe Text
queryDefinitionId :: Prelude.Maybe Prelude.Text,
    -- | The name of the query definition.
    QueryDefinition -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The query string to use for this definition. For more information, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html CloudWatch Logs Insights Query Syntax>.
    QueryDefinition -> Maybe Text
queryString :: Prelude.Maybe Prelude.Text,
    -- | The date that the query definition was most recently modified.
    QueryDefinition -> Maybe Natural
lastModified :: Prelude.Maybe Prelude.Natural
  }
  deriving (QueryDefinition -> QueryDefinition -> Bool
(QueryDefinition -> QueryDefinition -> Bool)
-> (QueryDefinition -> QueryDefinition -> Bool)
-> Eq QueryDefinition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueryDefinition -> QueryDefinition -> Bool
$c/= :: QueryDefinition -> QueryDefinition -> Bool
== :: QueryDefinition -> QueryDefinition -> Bool
$c== :: QueryDefinition -> QueryDefinition -> Bool
Prelude.Eq, ReadPrec [QueryDefinition]
ReadPrec QueryDefinition
Int -> ReadS QueryDefinition
ReadS [QueryDefinition]
(Int -> ReadS QueryDefinition)
-> ReadS [QueryDefinition]
-> ReadPrec QueryDefinition
-> ReadPrec [QueryDefinition]
-> Read QueryDefinition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [QueryDefinition]
$creadListPrec :: ReadPrec [QueryDefinition]
readPrec :: ReadPrec QueryDefinition
$creadPrec :: ReadPrec QueryDefinition
readList :: ReadS [QueryDefinition]
$creadList :: ReadS [QueryDefinition]
readsPrec :: Int -> ReadS QueryDefinition
$creadsPrec :: Int -> ReadS QueryDefinition
Prelude.Read, Int -> QueryDefinition -> ShowS
[QueryDefinition] -> ShowS
QueryDefinition -> String
(Int -> QueryDefinition -> ShowS)
-> (QueryDefinition -> String)
-> ([QueryDefinition] -> ShowS)
-> Show QueryDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueryDefinition] -> ShowS
$cshowList :: [QueryDefinition] -> ShowS
show :: QueryDefinition -> String
$cshow :: QueryDefinition -> String
showsPrec :: Int -> QueryDefinition -> ShowS
$cshowsPrec :: Int -> QueryDefinition -> ShowS
Prelude.Show, (forall x. QueryDefinition -> Rep QueryDefinition x)
-> (forall x. Rep QueryDefinition x -> QueryDefinition)
-> Generic QueryDefinition
forall x. Rep QueryDefinition x -> QueryDefinition
forall x. QueryDefinition -> Rep QueryDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep QueryDefinition x -> QueryDefinition
$cfrom :: forall x. QueryDefinition -> Rep QueryDefinition x
Prelude.Generic)

-- |
-- Create a value of 'QueryDefinition' 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:
--
-- 'logGroupNames', 'queryDefinition_logGroupNames' - If this query definition contains a list of log groups that it is
-- limited to, that list appears here.
--
-- 'queryDefinitionId', 'queryDefinition_queryDefinitionId' - The unique ID of the query definition.
--
-- 'name', 'queryDefinition_name' - The name of the query definition.
--
-- 'queryString', 'queryDefinition_queryString' - The query string to use for this definition. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html CloudWatch Logs Insights Query Syntax>.
--
-- 'lastModified', 'queryDefinition_lastModified' - The date that the query definition was most recently modified.
newQueryDefinition ::
  QueryDefinition
newQueryDefinition :: QueryDefinition
newQueryDefinition =
  QueryDefinition' :: Maybe [Text]
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Natural
-> QueryDefinition
QueryDefinition'
    { $sel:logGroupNames:QueryDefinition' :: Maybe [Text]
logGroupNames = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:queryDefinitionId:QueryDefinition' :: Maybe Text
queryDefinitionId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:QueryDefinition' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:queryString:QueryDefinition' :: Maybe Text
queryString = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:lastModified:QueryDefinition' :: Maybe Natural
lastModified = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | If this query definition contains a list of log groups that it is
-- limited to, that list appears here.
queryDefinition_logGroupNames :: Lens.Lens' QueryDefinition (Prelude.Maybe [Prelude.Text])
queryDefinition_logGroupNames :: (Maybe [Text] -> f (Maybe [Text]))
-> QueryDefinition -> f QueryDefinition
queryDefinition_logGroupNames = (QueryDefinition -> Maybe [Text])
-> (QueryDefinition -> Maybe [Text] -> QueryDefinition)
-> Lens
     QueryDefinition QueryDefinition (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryDefinition' {Maybe [Text]
logGroupNames :: Maybe [Text]
$sel:logGroupNames:QueryDefinition' :: QueryDefinition -> Maybe [Text]
logGroupNames} -> Maybe [Text]
logGroupNames) (\s :: QueryDefinition
s@QueryDefinition' {} Maybe [Text]
a -> QueryDefinition
s {$sel:logGroupNames:QueryDefinition' :: Maybe [Text]
logGroupNames = Maybe [Text]
a} :: QueryDefinition) ((Maybe [Text] -> f (Maybe [Text]))
 -> QueryDefinition -> f QueryDefinition)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> QueryDefinition
-> f QueryDefinition
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 unique ID of the query definition.
queryDefinition_queryDefinitionId :: Lens.Lens' QueryDefinition (Prelude.Maybe Prelude.Text)
queryDefinition_queryDefinitionId :: (Maybe Text -> f (Maybe Text))
-> QueryDefinition -> f QueryDefinition
queryDefinition_queryDefinitionId = (QueryDefinition -> Maybe Text)
-> (QueryDefinition -> Maybe Text -> QueryDefinition)
-> Lens QueryDefinition QueryDefinition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryDefinition' {Maybe Text
queryDefinitionId :: Maybe Text
$sel:queryDefinitionId:QueryDefinition' :: QueryDefinition -> Maybe Text
queryDefinitionId} -> Maybe Text
queryDefinitionId) (\s :: QueryDefinition
s@QueryDefinition' {} Maybe Text
a -> QueryDefinition
s {$sel:queryDefinitionId:QueryDefinition' :: Maybe Text
queryDefinitionId = Maybe Text
a} :: QueryDefinition)

-- | The name of the query definition.
queryDefinition_name :: Lens.Lens' QueryDefinition (Prelude.Maybe Prelude.Text)
queryDefinition_name :: (Maybe Text -> f (Maybe Text))
-> QueryDefinition -> f QueryDefinition
queryDefinition_name = (QueryDefinition -> Maybe Text)
-> (QueryDefinition -> Maybe Text -> QueryDefinition)
-> Lens QueryDefinition QueryDefinition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryDefinition' {Maybe Text
name :: Maybe Text
$sel:name:QueryDefinition' :: QueryDefinition -> Maybe Text
name} -> Maybe Text
name) (\s :: QueryDefinition
s@QueryDefinition' {} Maybe Text
a -> QueryDefinition
s {$sel:name:QueryDefinition' :: Maybe Text
name = Maybe Text
a} :: QueryDefinition)

-- | The query string to use for this definition. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html CloudWatch Logs Insights Query Syntax>.
queryDefinition_queryString :: Lens.Lens' QueryDefinition (Prelude.Maybe Prelude.Text)
queryDefinition_queryString :: (Maybe Text -> f (Maybe Text))
-> QueryDefinition -> f QueryDefinition
queryDefinition_queryString = (QueryDefinition -> Maybe Text)
-> (QueryDefinition -> Maybe Text -> QueryDefinition)
-> Lens QueryDefinition QueryDefinition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryDefinition' {Maybe Text
queryString :: Maybe Text
$sel:queryString:QueryDefinition' :: QueryDefinition -> Maybe Text
queryString} -> Maybe Text
queryString) (\s :: QueryDefinition
s@QueryDefinition' {} Maybe Text
a -> QueryDefinition
s {$sel:queryString:QueryDefinition' :: Maybe Text
queryString = Maybe Text
a} :: QueryDefinition)

-- | The date that the query definition was most recently modified.
queryDefinition_lastModified :: Lens.Lens' QueryDefinition (Prelude.Maybe Prelude.Natural)
queryDefinition_lastModified :: (Maybe Natural -> f (Maybe Natural))
-> QueryDefinition -> f QueryDefinition
queryDefinition_lastModified = (QueryDefinition -> Maybe Natural)
-> (QueryDefinition -> Maybe Natural -> QueryDefinition)
-> Lens
     QueryDefinition QueryDefinition (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryDefinition' {Maybe Natural
lastModified :: Maybe Natural
$sel:lastModified:QueryDefinition' :: QueryDefinition -> Maybe Natural
lastModified} -> Maybe Natural
lastModified) (\s :: QueryDefinition
s@QueryDefinition' {} Maybe Natural
a -> QueryDefinition
s {$sel:lastModified:QueryDefinition' :: Maybe Natural
lastModified = Maybe Natural
a} :: QueryDefinition)

instance Core.FromJSON QueryDefinition where
  parseJSON :: Value -> Parser QueryDefinition
parseJSON =
    String
-> (Object -> Parser QueryDefinition)
-> Value
-> Parser QueryDefinition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"QueryDefinition"
      ( \Object
x ->
          Maybe [Text]
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Natural
-> QueryDefinition
QueryDefinition'
            (Maybe [Text]
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Natural
 -> QueryDefinition)
-> Parser (Maybe [Text])
-> Parser
     (Maybe Text
      -> Maybe Text -> Maybe Text -> Maybe Natural -> QueryDefinition)
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
"logGroupNames" 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 Text
   -> Maybe Text -> Maybe Text -> Maybe Natural -> QueryDefinition)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> Maybe Text -> Maybe Natural -> QueryDefinition)
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
"queryDefinitionId")
            Parser
  (Maybe Text -> Maybe Text -> Maybe Natural -> QueryDefinition)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Natural -> QueryDefinition)
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 -> Maybe Natural -> QueryDefinition)
-> Parser (Maybe Text) -> Parser (Maybe Natural -> QueryDefinition)
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
"queryString")
            Parser (Maybe Natural -> QueryDefinition)
-> Parser (Maybe Natural) -> Parser QueryDefinition
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"lastModified")
      )

instance Prelude.Hashable QueryDefinition

instance Prelude.NFData QueryDefinition