{-# LANGUAGE UndecidableInstances #-}

-- | This module contains the default types and function that model aggregation
-- predicates.
module Hasura.RQL.IR.BoolExp.AggregationPredicates
  ( AggregationPredicatesImplementation (..),
    AggregationPredicate (..),
    AggregationPredicateArguments (..),
  )
where

import Data.Aeson
import Data.Aeson.Extended (ToJSONKeyValue (..))
import Data.Aeson.Key (fromText)
import Hasura.Prelude
import Hasura.RQL.IR.BoolExp (AnnBoolExp, OpExpG)
import Hasura.RQL.Types.Backend (Backend (Column))
import Hasura.RQL.Types.Backend qualified as B
import Hasura.RQL.Types.BackendType (BackendType)
import Hasura.RQL.Types.Relationships.Local (RelInfo)

-- | This type the default non-empty implementation of the
-- 'AggregationPredicates' type family of 'class Backend'.
--
-- This represents an _applied_ aggregation predicate, i.e. _not_ an aggegation
-- function in isolation.
--
-- In the default schema implementation, this type results from parsing graphql such as:
--
--    table(_where(
--             <relation>_aggregate:
--             {<functionname>: {
--                arguments: <arguments>,
--                predicate: <predicate>,
--                distinct: bool
--                }
--             }
--         ))
--      { ... }
--
-- Note that we make no attempt at modelling window functions or so-called
-- 'analytical' functions such as 'percentile_cont'.
data AggregationPredicatesImplementation (b :: BackendType) field = AggregationPredicatesImplementation
  { forall (b :: BackendType) field.
AggregationPredicatesImplementation b field -> RelInfo b
aggRelation :: RelInfo b,
    forall (b :: BackendType) field.
AggregationPredicatesImplementation b field -> AnnBoolExp b field
aggRowPermission :: AnnBoolExp b field,
    forall (b :: BackendType) field.
AggregationPredicatesImplementation b field
-> AggregationPredicate b field
aggPredicate :: AggregationPredicate b field
  }
  deriving stock ((forall m.
 Monoid m =>
 AggregationPredicatesImplementation b m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> AggregationPredicatesImplementation b a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> AggregationPredicatesImplementation b a -> m)
-> (forall a b.
    (a -> b -> b) -> b -> AggregationPredicatesImplementation b a -> b)
-> (forall a b.
    (a -> b -> b) -> b -> AggregationPredicatesImplementation b a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> AggregationPredicatesImplementation b a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> AggregationPredicatesImplementation b a -> b)
-> (forall a.
    (a -> a -> a) -> AggregationPredicatesImplementation b a -> a)
-> (forall a.
    (a -> a -> a) -> AggregationPredicatesImplementation b a -> a)
-> (forall a. AggregationPredicatesImplementation b a -> [a])
-> (forall a. AggregationPredicatesImplementation b a -> Bool)
-> (forall a. AggregationPredicatesImplementation b a -> Int)
-> (forall a.
    Eq a =>
    a -> AggregationPredicatesImplementation b a -> Bool)
-> (forall a.
    Ord a =>
    AggregationPredicatesImplementation b a -> a)
-> (forall a.
    Ord a =>
    AggregationPredicatesImplementation b a -> a)
-> (forall a.
    Num a =>
    AggregationPredicatesImplementation b a -> a)
-> (forall a.
    Num a =>
    AggregationPredicatesImplementation b a -> a)
-> Foldable (AggregationPredicatesImplementation b)
forall a.
Eq a =>
a -> AggregationPredicatesImplementation b a -> Bool
forall a. Num a => AggregationPredicatesImplementation b a -> a
forall a. Ord a => AggregationPredicatesImplementation b a -> a
forall m. Monoid m => AggregationPredicatesImplementation b m -> m
forall a. AggregationPredicatesImplementation b a -> Bool
forall a. AggregationPredicatesImplementation b a -> Int
forall a. AggregationPredicatesImplementation b a -> [a]
forall a.
(a -> a -> a) -> AggregationPredicatesImplementation b a -> a
forall m a.
Monoid m =>
(a -> m) -> AggregationPredicatesImplementation b a -> m
forall b a.
(b -> a -> b) -> b -> AggregationPredicatesImplementation b a -> b
forall a b.
(a -> b -> b) -> b -> AggregationPredicatesImplementation b a -> b
forall (b :: BackendType) a.
(Backend b, Eq a) =>
a -> AggregationPredicatesImplementation b a -> Bool
forall (b :: BackendType) a.
(Backend b, Num a) =>
AggregationPredicatesImplementation b a -> a
forall (b :: BackendType) a.
(Backend b, Ord a) =>
AggregationPredicatesImplementation b a -> a
forall (b :: BackendType) m.
(Backend b, Monoid m) =>
AggregationPredicatesImplementation b m -> m
forall (b :: BackendType) a.
Backend b =>
AggregationPredicatesImplementation b a -> Bool
forall (b :: BackendType) a.
Backend b =>
AggregationPredicatesImplementation b a -> Int
forall (b :: BackendType) a.
Backend b =>
AggregationPredicatesImplementation b a -> [a]
forall (b :: BackendType) a.
Backend b =>
(a -> a -> a) -> AggregationPredicatesImplementation b a -> a
forall (b :: BackendType) m a.
(Backend b, Monoid m) =>
(a -> m) -> AggregationPredicatesImplementation b a -> m
forall (b :: BackendType) b a.
Backend b =>
(b -> a -> b) -> b -> AggregationPredicatesImplementation b a -> b
forall (b :: BackendType) a b.
Backend b =>
(a -> b -> b) -> b -> AggregationPredicatesImplementation b a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall (b :: BackendType) m.
(Backend b, Monoid m) =>
AggregationPredicatesImplementation b m -> m
fold :: forall m. Monoid m => AggregationPredicatesImplementation b m -> m
$cfoldMap :: forall (b :: BackendType) m a.
(Backend b, Monoid m) =>
(a -> m) -> AggregationPredicatesImplementation b a -> m
foldMap :: forall m a.
Monoid m =>
(a -> m) -> AggregationPredicatesImplementation b a -> m
$cfoldMap' :: forall (b :: BackendType) m a.
(Backend b, Monoid m) =>
(a -> m) -> AggregationPredicatesImplementation b a -> m
foldMap' :: forall m a.
Monoid m =>
(a -> m) -> AggregationPredicatesImplementation b a -> m
$cfoldr :: forall (b :: BackendType) a b.
Backend b =>
(a -> b -> b) -> b -> AggregationPredicatesImplementation b a -> b
foldr :: forall a b.
(a -> b -> b) -> b -> AggregationPredicatesImplementation b a -> b
$cfoldr' :: forall (b :: BackendType) a b.
Backend b =>
(a -> b -> b) -> b -> AggregationPredicatesImplementation b a -> b
foldr' :: forall a b.
(a -> b -> b) -> b -> AggregationPredicatesImplementation b a -> b
$cfoldl :: forall (b :: BackendType) b a.
Backend b =>
(b -> a -> b) -> b -> AggregationPredicatesImplementation b a -> b
foldl :: forall b a.
(b -> a -> b) -> b -> AggregationPredicatesImplementation b a -> b
$cfoldl' :: forall (b :: BackendType) b a.
Backend b =>
(b -> a -> b) -> b -> AggregationPredicatesImplementation b a -> b
foldl' :: forall b a.
(b -> a -> b) -> b -> AggregationPredicatesImplementation b a -> b
$cfoldr1 :: forall (b :: BackendType) a.
Backend b =>
(a -> a -> a) -> AggregationPredicatesImplementation b a -> a
foldr1 :: forall a.
(a -> a -> a) -> AggregationPredicatesImplementation b a -> a
$cfoldl1 :: forall (b :: BackendType) a.
Backend b =>
(a -> a -> a) -> AggregationPredicatesImplementation b a -> a
foldl1 :: forall a.
(a -> a -> a) -> AggregationPredicatesImplementation b a -> a
$ctoList :: forall (b :: BackendType) a.
Backend b =>
AggregationPredicatesImplementation b a -> [a]
toList :: forall a. AggregationPredicatesImplementation b a -> [a]
$cnull :: forall (b :: BackendType) a.
Backend b =>
AggregationPredicatesImplementation b a -> Bool
null :: forall a. AggregationPredicatesImplementation b a -> Bool
$clength :: forall (b :: BackendType) a.
Backend b =>
AggregationPredicatesImplementation b a -> Int
length :: forall a. AggregationPredicatesImplementation b a -> Int
$celem :: forall (b :: BackendType) a.
(Backend b, Eq a) =>
a -> AggregationPredicatesImplementation b a -> Bool
elem :: forall a.
Eq a =>
a -> AggregationPredicatesImplementation b a -> Bool
$cmaximum :: forall (b :: BackendType) a.
(Backend b, Ord a) =>
AggregationPredicatesImplementation b a -> a
maximum :: forall a. Ord a => AggregationPredicatesImplementation b a -> a
$cminimum :: forall (b :: BackendType) a.
(Backend b, Ord a) =>
AggregationPredicatesImplementation b a -> a
minimum :: forall a. Ord a => AggregationPredicatesImplementation b a -> a
$csum :: forall (b :: BackendType) a.
(Backend b, Num a) =>
AggregationPredicatesImplementation b a -> a
sum :: forall a. Num a => AggregationPredicatesImplementation b a -> a
$cproduct :: forall (b :: BackendType) a.
(Backend b, Num a) =>
AggregationPredicatesImplementation b a -> a
product :: forall a. Num a => AggregationPredicatesImplementation b a -> a
Foldable, Functor (AggregationPredicatesImplementation b)
Foldable (AggregationPredicatesImplementation b)
Functor (AggregationPredicatesImplementation b)
-> Foldable (AggregationPredicatesImplementation b)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b)
    -> AggregationPredicatesImplementation b a
    -> f (AggregationPredicatesImplementation b b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    AggregationPredicatesImplementation b (f a)
    -> f (AggregationPredicatesImplementation b a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b)
    -> AggregationPredicatesImplementation b a
    -> m (AggregationPredicatesImplementation b b))
-> (forall (m :: * -> *) a.
    Monad m =>
    AggregationPredicatesImplementation b (m a)
    -> m (AggregationPredicatesImplementation b a))
-> Traversable (AggregationPredicatesImplementation b)
forall {b :: BackendType}.
Backend b =>
Functor (AggregationPredicatesImplementation b)
forall (b :: BackendType).
Backend b =>
Foldable (AggregationPredicatesImplementation b)
forall (b :: BackendType) (m :: * -> *) a.
(Backend b, Monad m) =>
AggregationPredicatesImplementation b (m a)
-> m (AggregationPredicatesImplementation b a)
forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Applicative f) =>
AggregationPredicatesImplementation b (f a)
-> f (AggregationPredicatesImplementation b a)
forall (b :: BackendType) (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b)
-> AggregationPredicatesImplementation b a
-> m (AggregationPredicatesImplementation b b)
forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b)
-> AggregationPredicatesImplementation b a
-> f (AggregationPredicatesImplementation b b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
AggregationPredicatesImplementation b (m a)
-> m (AggregationPredicatesImplementation b a)
forall (f :: * -> *) a.
Applicative f =>
AggregationPredicatesImplementation b (f a)
-> f (AggregationPredicatesImplementation b a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> AggregationPredicatesImplementation b a
-> m (AggregationPredicatesImplementation b b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> AggregationPredicatesImplementation b a
-> f (AggregationPredicatesImplementation b b)
$ctraverse :: forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b)
-> AggregationPredicatesImplementation b a
-> f (AggregationPredicatesImplementation b b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> AggregationPredicatesImplementation b a
-> f (AggregationPredicatesImplementation b b)
$csequenceA :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Applicative f) =>
AggregationPredicatesImplementation b (f a)
-> f (AggregationPredicatesImplementation b a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
AggregationPredicatesImplementation b (f a)
-> f (AggregationPredicatesImplementation b a)
$cmapM :: forall (b :: BackendType) (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b)
-> AggregationPredicatesImplementation b a
-> m (AggregationPredicatesImplementation b b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> AggregationPredicatesImplementation b a
-> m (AggregationPredicatesImplementation b b)
$csequence :: forall (b :: BackendType) (m :: * -> *) a.
(Backend b, Monad m) =>
AggregationPredicatesImplementation b (m a)
-> m (AggregationPredicatesImplementation b a)
sequence :: forall (m :: * -> *) a.
Monad m =>
AggregationPredicatesImplementation b (m a)
-> m (AggregationPredicatesImplementation b a)
Traversable, (forall a b.
 (a -> b)
 -> AggregationPredicatesImplementation b a
 -> AggregationPredicatesImplementation b b)
-> (forall a b.
    a
    -> AggregationPredicatesImplementation b b
    -> AggregationPredicatesImplementation b a)
-> Functor (AggregationPredicatesImplementation b)
forall a b.
a
-> AggregationPredicatesImplementation b b
-> AggregationPredicatesImplementation b a
forall a b.
(a -> b)
-> AggregationPredicatesImplementation b a
-> AggregationPredicatesImplementation b b
forall (b :: BackendType) a b.
Backend b =>
a
-> AggregationPredicatesImplementation b b
-> AggregationPredicatesImplementation b a
forall (b :: BackendType) a b.
Backend b =>
(a -> b)
-> AggregationPredicatesImplementation b a
-> AggregationPredicatesImplementation b b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (b :: BackendType) a b.
Backend b =>
(a -> b)
-> AggregationPredicatesImplementation b a
-> AggregationPredicatesImplementation b b
fmap :: forall a b.
(a -> b)
-> AggregationPredicatesImplementation b a
-> AggregationPredicatesImplementation b b
$c<$ :: forall (b :: BackendType) a b.
Backend b =>
a
-> AggregationPredicatesImplementation b b
-> AggregationPredicatesImplementation b a
<$ :: forall a b.
a
-> AggregationPredicatesImplementation b b
-> AggregationPredicatesImplementation b a
Functor, (forall x.
 AggregationPredicatesImplementation b field
 -> Rep (AggregationPredicatesImplementation b field) x)
-> (forall x.
    Rep (AggregationPredicatesImplementation b field) x
    -> AggregationPredicatesImplementation b field)
-> Generic (AggregationPredicatesImplementation b field)
forall x.
Rep (AggregationPredicatesImplementation b field) x
-> AggregationPredicatesImplementation b field
forall x.
AggregationPredicatesImplementation b field
-> Rep (AggregationPredicatesImplementation b field) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) field x.
Rep (AggregationPredicatesImplementation b field) x
-> AggregationPredicatesImplementation b field
forall (b :: BackendType) field x.
AggregationPredicatesImplementation b field
-> Rep (AggregationPredicatesImplementation b field) x
$cfrom :: forall (b :: BackendType) field x.
AggregationPredicatesImplementation b field
-> Rep (AggregationPredicatesImplementation b field) x
from :: forall x.
AggregationPredicatesImplementation b field
-> Rep (AggregationPredicatesImplementation b field) x
$cto :: forall (b :: BackendType) field x.
Rep (AggregationPredicatesImplementation b field) x
-> AggregationPredicatesImplementation b field
to :: forall x.
Rep (AggregationPredicatesImplementation b field) x
-> AggregationPredicatesImplementation b field
Generic)

deriving instance
  ( B.Backend b,
    Eq (AggregationPredicate b field),
    Eq (AnnBoolExp b field)
  ) =>
  Eq (AggregationPredicatesImplementation b field)

deriving instance
  ( B.Backend b,
    Show (AggregationPredicate b field),
    Show (AnnBoolExp b field)
  ) =>
  Show (AggregationPredicatesImplementation b field)

instance
  ( B.Backend b,
    Hashable (AggregationPredicate b field),
    Hashable (AnnBoolExp b field)
  ) =>
  Hashable (AggregationPredicatesImplementation b field)

instance
  ( B.Backend b,
    NFData (AggregationPredicate b field),
    NFData (AnnBoolExp b field)
  ) =>
  NFData (AggregationPredicatesImplementation b field)

instance
  ( ToJSON (AnnBoolExp b field),
    ToJSON (AggregationPredicate b field),
    ToJSON (OpExpG b field),
    B.Backend b
  ) =>
  ToJSON (AggregationPredicatesImplementation b field)

instance
  ( Backend b,
    ToJSONKeyValue (AggregationPredicate b field)
  ) =>
  ToJSONKeyValue (AggregationPredicatesImplementation b field)
  where
  toJSONKeyValue :: AggregationPredicatesImplementation b field -> Pair
toJSONKeyValue AggregationPredicatesImplementation {RelInfo b
AnnBoolExp b field
AggregationPredicate b field
aggRelation :: forall (b :: BackendType) field.
AggregationPredicatesImplementation b field -> RelInfo b
aggRowPermission :: forall (b :: BackendType) field.
AggregationPredicatesImplementation b field -> AnnBoolExp b field
aggPredicate :: forall (b :: BackendType) field.
AggregationPredicatesImplementation b field
-> AggregationPredicate b field
aggRelation :: RelInfo b
aggRowPermission :: AnnBoolExp b field
aggPredicate :: AggregationPredicate b field
..} =
    ( Text -> Key
fromText Text
"aggregation_predicates",
      [(Text, Value)] -> Value
forall a. ToJSON a => a -> Value
toJSON
        [ (Text
"predicate" :: Text, Pair -> Value
forall a. ToJSON a => a -> Value
toJSON (Pair -> Value) -> Pair -> Value
forall a b. (a -> b) -> a -> b
$ AggregationPredicate b field -> Pair
forall a. ToJSONKeyValue a => a -> Pair
toJSONKeyValue AggregationPredicate b field
aggPredicate),
          (Text
"relation", RelInfo b -> Value
forall a. ToJSON a => a -> Value
toJSON RelInfo b
aggRelation)
        ]
    )

data AggregationPredicate (b :: BackendType) field = AggregationPredicate
  { forall (b :: BackendType) field.
AggregationPredicate b field -> Text
aggPredFunctionName :: Text,
    forall (b :: BackendType) field.
AggregationPredicate b field -> Bool
aggPredDistinct :: Bool,
    forall (b :: BackendType) field.
AggregationPredicate b field -> Maybe (AnnBoolExp b field)
aggPredFilter :: Maybe (AnnBoolExp b field),
    forall (b :: BackendType) field.
AggregationPredicate b field -> AggregationPredicateArguments b
aggPredArguments :: AggregationPredicateArguments b,
    forall (b :: BackendType) field.
AggregationPredicate b field -> [OpExpG b field]
aggPredPredicate :: [OpExpG b field]
  }
  deriving stock ((forall m. Monoid m => AggregationPredicate b m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> AggregationPredicate b a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> AggregationPredicate b a -> m)
-> (forall a b.
    (a -> b -> b) -> b -> AggregationPredicate b a -> b)
-> (forall a b.
    (a -> b -> b) -> b -> AggregationPredicate b a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> AggregationPredicate b a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> AggregationPredicate b a -> b)
-> (forall a. (a -> a -> a) -> AggregationPredicate b a -> a)
-> (forall a. (a -> a -> a) -> AggregationPredicate b a -> a)
-> (forall a. AggregationPredicate b a -> [a])
-> (forall a. AggregationPredicate b a -> Bool)
-> (forall a. AggregationPredicate b a -> Int)
-> (forall a. Eq a => a -> AggregationPredicate b a -> Bool)
-> (forall a. Ord a => AggregationPredicate b a -> a)
-> (forall a. Ord a => AggregationPredicate b a -> a)
-> (forall a. Num a => AggregationPredicate b a -> a)
-> (forall a. Num a => AggregationPredicate b a -> a)
-> Foldable (AggregationPredicate b)
forall a. Eq a => a -> AggregationPredicate b a -> Bool
forall a. Num a => AggregationPredicate b a -> a
forall a. Ord a => AggregationPredicate b a -> a
forall m. Monoid m => AggregationPredicate b m -> m
forall a. AggregationPredicate b a -> Bool
forall a. AggregationPredicate b a -> Int
forall a. AggregationPredicate b a -> [a]
forall a. (a -> a -> a) -> AggregationPredicate b a -> a
forall m a. Monoid m => (a -> m) -> AggregationPredicate b a -> m
forall b a. (b -> a -> b) -> b -> AggregationPredicate b a -> b
forall a b. (a -> b -> b) -> b -> AggregationPredicate b a -> b
forall (b :: BackendType) a.
(Backend b, Eq a) =>
a -> AggregationPredicate b a -> Bool
forall (b :: BackendType) a.
(Backend b, Num a) =>
AggregationPredicate b a -> a
forall (b :: BackendType) a.
(Backend b, Ord a) =>
AggregationPredicate b a -> a
forall (b :: BackendType) m.
(Backend b, Monoid m) =>
AggregationPredicate b m -> m
forall (b :: BackendType) a.
Backend b =>
AggregationPredicate b a -> Bool
forall (b :: BackendType) a.
Backend b =>
AggregationPredicate b a -> Int
forall (b :: BackendType) a.
Backend b =>
AggregationPredicate b a -> [a]
forall (b :: BackendType) a.
Backend b =>
(a -> a -> a) -> AggregationPredicate b a -> a
forall (b :: BackendType) m a.
(Backend b, Monoid m) =>
(a -> m) -> AggregationPredicate b a -> m
forall (b :: BackendType) b a.
Backend b =>
(b -> a -> b) -> b -> AggregationPredicate b a -> b
forall (b :: BackendType) a b.
Backend b =>
(a -> b -> b) -> b -> AggregationPredicate b a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall (b :: BackendType) m.
(Backend b, Monoid m) =>
AggregationPredicate b m -> m
fold :: forall m. Monoid m => AggregationPredicate b m -> m
$cfoldMap :: forall (b :: BackendType) m a.
(Backend b, Monoid m) =>
(a -> m) -> AggregationPredicate b a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> AggregationPredicate b a -> m
$cfoldMap' :: forall (b :: BackendType) m a.
(Backend b, Monoid m) =>
(a -> m) -> AggregationPredicate b a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> AggregationPredicate b a -> m
$cfoldr :: forall (b :: BackendType) a b.
Backend b =>
(a -> b -> b) -> b -> AggregationPredicate b a -> b
foldr :: forall a b. (a -> b -> b) -> b -> AggregationPredicate b a -> b
$cfoldr' :: forall (b :: BackendType) a b.
Backend b =>
(a -> b -> b) -> b -> AggregationPredicate b a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> AggregationPredicate b a -> b
$cfoldl :: forall (b :: BackendType) b a.
Backend b =>
(b -> a -> b) -> b -> AggregationPredicate b a -> b
foldl :: forall b a. (b -> a -> b) -> b -> AggregationPredicate b a -> b
$cfoldl' :: forall (b :: BackendType) b a.
Backend b =>
(b -> a -> b) -> b -> AggregationPredicate b a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> AggregationPredicate b a -> b
$cfoldr1 :: forall (b :: BackendType) a.
Backend b =>
(a -> a -> a) -> AggregationPredicate b a -> a
foldr1 :: forall a. (a -> a -> a) -> AggregationPredicate b a -> a
$cfoldl1 :: forall (b :: BackendType) a.
Backend b =>
(a -> a -> a) -> AggregationPredicate b a -> a
foldl1 :: forall a. (a -> a -> a) -> AggregationPredicate b a -> a
$ctoList :: forall (b :: BackendType) a.
Backend b =>
AggregationPredicate b a -> [a]
toList :: forall a. AggregationPredicate b a -> [a]
$cnull :: forall (b :: BackendType) a.
Backend b =>
AggregationPredicate b a -> Bool
null :: forall a. AggregationPredicate b a -> Bool
$clength :: forall (b :: BackendType) a.
Backend b =>
AggregationPredicate b a -> Int
length :: forall a. AggregationPredicate b a -> Int
$celem :: forall (b :: BackendType) a.
(Backend b, Eq a) =>
a -> AggregationPredicate b a -> Bool
elem :: forall a. Eq a => a -> AggregationPredicate b a -> Bool
$cmaximum :: forall (b :: BackendType) a.
(Backend b, Ord a) =>
AggregationPredicate b a -> a
maximum :: forall a. Ord a => AggregationPredicate b a -> a
$cminimum :: forall (b :: BackendType) a.
(Backend b, Ord a) =>
AggregationPredicate b a -> a
minimum :: forall a. Ord a => AggregationPredicate b a -> a
$csum :: forall (b :: BackendType) a.
(Backend b, Num a) =>
AggregationPredicate b a -> a
sum :: forall a. Num a => AggregationPredicate b a -> a
$cproduct :: forall (b :: BackendType) a.
(Backend b, Num a) =>
AggregationPredicate b a -> a
product :: forall a. Num a => AggregationPredicate b a -> a
Foldable, Functor (AggregationPredicate b)
Foldable (AggregationPredicate b)
Functor (AggregationPredicate b)
-> Foldable (AggregationPredicate b)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b)
    -> AggregationPredicate b a -> f (AggregationPredicate b b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    AggregationPredicate b (f a) -> f (AggregationPredicate b a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b)
    -> AggregationPredicate b a -> m (AggregationPredicate b b))
-> (forall (m :: * -> *) a.
    Monad m =>
    AggregationPredicate b (m a) -> m (AggregationPredicate b a))
-> Traversable (AggregationPredicate b)
forall (b :: BackendType).
Backend b =>
Functor (AggregationPredicate b)
forall (b :: BackendType).
Backend b =>
Foldable (AggregationPredicate b)
forall (b :: BackendType) (m :: * -> *) a.
(Backend b, Monad m) =>
AggregationPredicate b (m a) -> m (AggregationPredicate b a)
forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Applicative f) =>
AggregationPredicate b (f a) -> f (AggregationPredicate b a)
forall (b :: BackendType) (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b)
-> AggregationPredicate b a -> m (AggregationPredicate b b)
forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b)
-> AggregationPredicate b a -> f (AggregationPredicate b b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
AggregationPredicate b (m a) -> m (AggregationPredicate b a)
forall (f :: * -> *) a.
Applicative f =>
AggregationPredicate b (f a) -> f (AggregationPredicate b a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> AggregationPredicate b a -> m (AggregationPredicate b b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> AggregationPredicate b a -> f (AggregationPredicate b b)
$ctraverse :: forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b)
-> AggregationPredicate b a -> f (AggregationPredicate b b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> AggregationPredicate b a -> f (AggregationPredicate b b)
$csequenceA :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Applicative f) =>
AggregationPredicate b (f a) -> f (AggregationPredicate b a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
AggregationPredicate b (f a) -> f (AggregationPredicate b a)
$cmapM :: forall (b :: BackendType) (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b)
-> AggregationPredicate b a -> m (AggregationPredicate b b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> AggregationPredicate b a -> m (AggregationPredicate b b)
$csequence :: forall (b :: BackendType) (m :: * -> *) a.
(Backend b, Monad m) =>
AggregationPredicate b (m a) -> m (AggregationPredicate b a)
sequence :: forall (m :: * -> *) a.
Monad m =>
AggregationPredicate b (m a) -> m (AggregationPredicate b a)
Traversable, (forall a b.
 (a -> b) -> AggregationPredicate b a -> AggregationPredicate b b)
-> (forall a b.
    a -> AggregationPredicate b b -> AggregationPredicate b a)
-> Functor (AggregationPredicate b)
forall a b.
a -> AggregationPredicate b b -> AggregationPredicate b a
forall a b.
(a -> b) -> AggregationPredicate b a -> AggregationPredicate b b
forall (b :: BackendType) a b.
Backend b =>
a -> AggregationPredicate b b -> AggregationPredicate b a
forall (b :: BackendType) a b.
Backend b =>
(a -> b) -> AggregationPredicate b a -> AggregationPredicate b b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (b :: BackendType) a b.
Backend b =>
(a -> b) -> AggregationPredicate b a -> AggregationPredicate b b
fmap :: forall a b.
(a -> b) -> AggregationPredicate b a -> AggregationPredicate b b
$c<$ :: forall (b :: BackendType) a b.
Backend b =>
a -> AggregationPredicate b b -> AggregationPredicate b a
<$ :: forall a b.
a -> AggregationPredicate b b -> AggregationPredicate b a
Functor, (forall x.
 AggregationPredicate b field
 -> Rep (AggregationPredicate b field) x)
-> (forall x.
    Rep (AggregationPredicate b field) x
    -> AggregationPredicate b field)
-> Generic (AggregationPredicate b field)
forall x.
Rep (AggregationPredicate b field) x
-> AggregationPredicate b field
forall x.
AggregationPredicate b field
-> Rep (AggregationPredicate b field) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) field x.
Rep (AggregationPredicate b field) x
-> AggregationPredicate b field
forall (b :: BackendType) field x.
AggregationPredicate b field
-> Rep (AggregationPredicate b field) x
$cfrom :: forall (b :: BackendType) field x.
AggregationPredicate b field
-> Rep (AggregationPredicate b field) x
from :: forall x.
AggregationPredicate b field
-> Rep (AggregationPredicate b field) x
$cto :: forall (b :: BackendType) field x.
Rep (AggregationPredicate b field) x
-> AggregationPredicate b field
to :: forall x.
Rep (AggregationPredicate b field) x
-> AggregationPredicate b field
Generic)

deriving instance
  ( B.Backend b,
    Eq (AnnBoolExp b field),
    Eq (OpExpG b field),
    Eq (AggregationPredicateArguments b)
  ) =>
  Eq (AggregationPredicate b field)

deriving instance
  ( B.Backend b,
    Show (AnnBoolExp b field),
    Show (OpExpG b field),
    Show (AggregationPredicateArguments b)
  ) =>
  Show (AggregationPredicate b field)

instance
  ( B.Backend b,
    Hashable (B.BooleanOperators b field),
    Hashable (AnnBoolExp b field),
    Hashable field
  ) =>
  Hashable (AggregationPredicate b field)

instance
  ( B.Backend b,
    NFData (AggregationPredicateArguments b),
    NFData (AnnBoolExp b field),
    NFData (OpExpG b field)
  ) =>
  NFData (AggregationPredicate b field)

instance
  ( ToJSON (AggregationPredicateArguments b),
    ToJSON (AnnBoolExp b field),
    ToJSONKeyValue (OpExpG b field)
  ) =>
  ToJSONKeyValue (AggregationPredicate b field)
  where
  toJSONKeyValue :: AggregationPredicate b field -> Pair
toJSONKeyValue AggregationPredicate {Bool
[OpExpG b field]
Maybe (AnnBoolExp b field)
Text
AggregationPredicateArguments b
aggPredFunctionName :: forall (b :: BackendType) field.
AggregationPredicate b field -> Text
aggPredDistinct :: forall (b :: BackendType) field.
AggregationPredicate b field -> Bool
aggPredFilter :: forall (b :: BackendType) field.
AggregationPredicate b field -> Maybe (AnnBoolExp b field)
aggPredArguments :: forall (b :: BackendType) field.
AggregationPredicate b field -> AggregationPredicateArguments b
aggPredPredicate :: forall (b :: BackendType) field.
AggregationPredicate b field -> [OpExpG b field]
aggPredFunctionName :: Text
aggPredDistinct :: Bool
aggPredFilter :: Maybe (AnnBoolExp b field)
aggPredArguments :: AggregationPredicateArguments b
aggPredPredicate :: [OpExpG b field]
..} =
    ( Text -> Key
fromText Text
aggPredFunctionName,
      [(Text, Value)] -> Value
forall a. ToJSON a => a -> Value
toJSON
        [ (Text
"aggPredDistinct" :: Text, Bool -> Value
forall a. ToJSON a => a -> Value
toJSON Bool
aggPredDistinct),
          (Text
"aggPredFilter", Maybe (AnnBoolExp b field) -> Value
forall a. ToJSON a => a -> Value
toJSON Maybe (AnnBoolExp b field)
aggPredFilter),
          (Text
"aggPredArguments", AggregationPredicateArguments b -> Value
forall a. ToJSON a => a -> Value
toJSON AggregationPredicateArguments b
aggPredArguments),
          (Text
"aggPredPredicate", [Pair] -> Value
forall a. ToJSON a => a -> Value
toJSON ((OpExpG b field -> Pair) -> [OpExpG b field] -> [Pair]
forall a b. (a -> b) -> [a] -> [b]
map OpExpG b field -> Pair
forall a. ToJSONKeyValue a => a -> Pair
toJSONKeyValue [OpExpG b field]
aggPredPredicate))
        ]
    )

data AggregationPredicateArguments (b :: BackendType)
  = AggregationPredicateArgumentsStar
  | AggregationPredicateArguments (NonEmpty (Column b))
  deriving stock ((forall x.
 AggregationPredicateArguments b
 -> Rep (AggregationPredicateArguments b) x)
-> (forall x.
    Rep (AggregationPredicateArguments b) x
    -> AggregationPredicateArguments b)
-> Generic (AggregationPredicateArguments b)
forall x.
Rep (AggregationPredicateArguments b) x
-> AggregationPredicateArguments b
forall x.
AggregationPredicateArguments b
-> Rep (AggregationPredicateArguments b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x.
Rep (AggregationPredicateArguments b) x
-> AggregationPredicateArguments b
forall (b :: BackendType) x.
AggregationPredicateArguments b
-> Rep (AggregationPredicateArguments b) x
$cfrom :: forall (b :: BackendType) x.
AggregationPredicateArguments b
-> Rep (AggregationPredicateArguments b) x
from :: forall x.
AggregationPredicateArguments b
-> Rep (AggregationPredicateArguments b) x
$cto :: forall (b :: BackendType) x.
Rep (AggregationPredicateArguments b) x
-> AggregationPredicateArguments b
to :: forall x.
Rep (AggregationPredicateArguments b) x
-> AggregationPredicateArguments b
Generic)

deriving instance (B.Backend b) => Eq (AggregationPredicateArguments b)

deriving instance (B.Backend b) => Show (AggregationPredicateArguments b)

instance (Backend b) => Hashable (AggregationPredicateArguments b)

instance (Backend b) => NFData (AggregationPredicateArguments b)

instance (Backend b) => ToJSON (AggregationPredicateArguments b)