{-# 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.CloudTrail.Types.Query
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudTrail.Types.Query where

import Amazonka.CloudTrail.Types.QueryStatus
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | A SQL string of criteria about events that you want to collect in an
-- event data store.
--
-- /See:/ 'newQuery' smart constructor.
data Query = Query'
  { -- | The creation time of a query.
    Query -> Maybe POSIX
creationTime :: Prelude.Maybe Data.POSIX,
    -- | The ID of a query.
    Query -> Maybe Text
queryId :: Prelude.Maybe Prelude.Text,
    -- | The status of the query. This can be @QUEUED@, @RUNNING@, @FINISHED@,
    -- @FAILED@, @TIMED_OUT@, or @CANCELLED@.
    Query -> Maybe QueryStatus
queryStatus :: Prelude.Maybe QueryStatus
  }
  deriving (Query -> Query -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Query -> Query -> Bool
$c/= :: Query -> Query -> Bool
== :: Query -> Query -> Bool
$c== :: Query -> Query -> Bool
Prelude.Eq, ReadPrec [Query]
ReadPrec Query
Int -> ReadS Query
ReadS [Query]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Query]
$creadListPrec :: ReadPrec [Query]
readPrec :: ReadPrec Query
$creadPrec :: ReadPrec Query
readList :: ReadS [Query]
$creadList :: ReadS [Query]
readsPrec :: Int -> ReadS Query
$creadsPrec :: Int -> ReadS Query
Prelude.Read, Int -> Query -> ShowS
[Query] -> ShowS
Query -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Query] -> ShowS
$cshowList :: [Query] -> ShowS
show :: Query -> String
$cshow :: Query -> String
showsPrec :: Int -> Query -> ShowS
$cshowsPrec :: Int -> Query -> ShowS
Prelude.Show, forall x. Rep Query x -> Query
forall x. Query -> Rep Query x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Query x -> Query
$cfrom :: forall x. Query -> Rep Query x
Prelude.Generic)

-- |
-- Create a value of 'Query' 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:
--
-- 'creationTime', 'query_creationTime' - The creation time of a query.
--
-- 'queryId', 'query_queryId' - The ID of a query.
--
-- 'queryStatus', 'query_queryStatus' - The status of the query. This can be @QUEUED@, @RUNNING@, @FINISHED@,
-- @FAILED@, @TIMED_OUT@, or @CANCELLED@.
newQuery ::
  Query
newQuery :: Query
newQuery =
  Query'
    { $sel:creationTime:Query' :: Maybe POSIX
creationTime = forall a. Maybe a
Prelude.Nothing,
      $sel:queryId:Query' :: Maybe Text
queryId = forall a. Maybe a
Prelude.Nothing,
      $sel:queryStatus:Query' :: Maybe QueryStatus
queryStatus = forall a. Maybe a
Prelude.Nothing
    }

-- | The creation time of a query.
query_creationTime :: Lens.Lens' Query (Prelude.Maybe Prelude.UTCTime)
query_creationTime :: Lens' Query (Maybe UTCTime)
query_creationTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Query' {Maybe POSIX
creationTime :: Maybe POSIX
$sel:creationTime:Query' :: Query -> Maybe POSIX
creationTime} -> Maybe POSIX
creationTime) (\s :: Query
s@Query' {} Maybe POSIX
a -> Query
s {$sel:creationTime:Query' :: Maybe POSIX
creationTime = Maybe POSIX
a} :: Query) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The ID of a query.
query_queryId :: Lens.Lens' Query (Prelude.Maybe Prelude.Text)
query_queryId :: Lens' Query (Maybe Text)
query_queryId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Query' {Maybe Text
queryId :: Maybe Text
$sel:queryId:Query' :: Query -> Maybe Text
queryId} -> Maybe Text
queryId) (\s :: Query
s@Query' {} Maybe Text
a -> Query
s {$sel:queryId:Query' :: Maybe Text
queryId = Maybe Text
a} :: Query)

-- | The status of the query. This can be @QUEUED@, @RUNNING@, @FINISHED@,
-- @FAILED@, @TIMED_OUT@, or @CANCELLED@.
query_queryStatus :: Lens.Lens' Query (Prelude.Maybe QueryStatus)
query_queryStatus :: Lens' Query (Maybe QueryStatus)
query_queryStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Query' {Maybe QueryStatus
queryStatus :: Maybe QueryStatus
$sel:queryStatus:Query' :: Query -> Maybe QueryStatus
queryStatus} -> Maybe QueryStatus
queryStatus) (\s :: Query
s@Query' {} Maybe QueryStatus
a -> Query
s {$sel:queryStatus:Query' :: Maybe QueryStatus
queryStatus = Maybe QueryStatus
a} :: Query)

instance Data.FromJSON Query where
  parseJSON :: Value -> Parser Query
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Query"
      ( \Object
x ->
          Maybe POSIX -> Maybe Text -> Maybe QueryStatus -> Query
Query'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"CreationTime")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"QueryId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"QueryStatus")
      )

instance Prelude.Hashable Query where
  hashWithSalt :: Int -> Query -> Int
hashWithSalt Int
_salt Query' {Maybe Text
Maybe POSIX
Maybe QueryStatus
queryStatus :: Maybe QueryStatus
queryId :: Maybe Text
creationTime :: Maybe POSIX
$sel:queryStatus:Query' :: Query -> Maybe QueryStatus
$sel:queryId:Query' :: Query -> Maybe Text
$sel:creationTime:Query' :: Query -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
creationTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
queryId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe QueryStatus
queryStatus

instance Prelude.NFData Query where
  rnf :: Query -> ()
rnf Query' {Maybe Text
Maybe POSIX
Maybe QueryStatus
queryStatus :: Maybe QueryStatus
queryId :: Maybe Text
creationTime :: Maybe POSIX
$sel:queryStatus:Query' :: Query -> Maybe QueryStatus
$sel:queryId:Query' :: Query -> Maybe Text
$sel:creationTime:Query' :: Query -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
creationTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
queryId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe QueryStatus
queryStatus