{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}

module Hasura.RQL.IR.Update
  ( AnnotatedUpdate,
    AnnotatedUpdateG (..),
    auTable,
    auUpdatePermissions,
    auCheck,
    auUpdateVariant,
    auOutput,
    auAllCols,
    auNamingConvention,
    auValidateInput,
  )
where

import Control.Lens.TH (makeLenses)
import Data.Kind (Type)
import Hasura.Prelude
import Hasura.RQL.IR.BoolExp
import Hasura.RQL.IR.Returning
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.BackendType
import Hasura.RQL.Types.Column
import Hasura.RQL.Types.Common
import Hasura.RQL.Types.NamingCase (NamingCase)
import Hasura.RQL.Types.Permission

--------------------------------------------------------------------------------

data AnnotatedUpdateG (b :: BackendType) (r :: Type) v = AnnotatedUpdateG
  { forall (b :: BackendType) r v.
AnnotatedUpdateG b r v -> TableName b
_auTable :: TableName b,
    forall (b :: BackendType) r v.
AnnotatedUpdateG b r v -> AnnBoolExp b v
_auUpdatePermissions :: AnnBoolExp b v,
    forall (b :: BackendType) r v.
AnnotatedUpdateG b r v -> AnnBoolExp b v
_auCheck :: AnnBoolExp b v,
    forall (b :: BackendType) r v.
AnnotatedUpdateG b r v -> UpdateVariant b v
_auUpdateVariant :: UpdateVariant b v,
    -- we don't prepare the arguments for returning
    -- however the session variable can still be
    -- converted as desired

    -- | Selection set
    forall (b :: BackendType) r v.
AnnotatedUpdateG b r v -> MutationOutputG b r v
_auOutput :: MutationOutputG b r v,
    forall (b :: BackendType) r v.
AnnotatedUpdateG b r v -> [ColumnInfo b]
_auAllCols :: [ColumnInfo b],
    forall (b :: BackendType) r v.
AnnotatedUpdateG b r v -> Maybe NamingCase
_auNamingConvention :: Maybe NamingCase,
    forall (b :: BackendType) r v.
AnnotatedUpdateG b r v -> Maybe (ValidateInput ResolvedWebhook)
_auValidateInput :: Maybe (ValidateInput ResolvedWebhook)
  }
  deriving stock ((forall a b.
 (a -> b) -> AnnotatedUpdateG b r a -> AnnotatedUpdateG b r b)
-> (forall a b.
    a -> AnnotatedUpdateG b r b -> AnnotatedUpdateG b r a)
-> Functor (AnnotatedUpdateG b r)
forall a b. a -> AnnotatedUpdateG b r b -> AnnotatedUpdateG b r a
forall a b.
(a -> b) -> AnnotatedUpdateG b r a -> AnnotatedUpdateG b r b
forall (b :: BackendType) r a b.
Backend b =>
a -> AnnotatedUpdateG b r b -> AnnotatedUpdateG b r a
forall (b :: BackendType) r a b.
Backend b =>
(a -> b) -> AnnotatedUpdateG b r a -> AnnotatedUpdateG b r 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) r a b.
Backend b =>
(a -> b) -> AnnotatedUpdateG b r a -> AnnotatedUpdateG b r b
fmap :: forall a b.
(a -> b) -> AnnotatedUpdateG b r a -> AnnotatedUpdateG b r b
$c<$ :: forall (b :: BackendType) r a b.
Backend b =>
a -> AnnotatedUpdateG b r b -> AnnotatedUpdateG b r a
<$ :: forall a b. a -> AnnotatedUpdateG b r b -> AnnotatedUpdateG b r a
Functor, (forall m. Monoid m => AnnotatedUpdateG b r m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> AnnotatedUpdateG b r a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> AnnotatedUpdateG b r a -> m)
-> (forall a b. (a -> b -> b) -> b -> AnnotatedUpdateG b r a -> b)
-> (forall a b. (a -> b -> b) -> b -> AnnotatedUpdateG b r a -> b)
-> (forall b a. (b -> a -> b) -> b -> AnnotatedUpdateG b r a -> b)
-> (forall b a. (b -> a -> b) -> b -> AnnotatedUpdateG b r a -> b)
-> (forall a. (a -> a -> a) -> AnnotatedUpdateG b r a -> a)
-> (forall a. (a -> a -> a) -> AnnotatedUpdateG b r a -> a)
-> (forall a. AnnotatedUpdateG b r a -> [a])
-> (forall a. AnnotatedUpdateG b r a -> Bool)
-> (forall a. AnnotatedUpdateG b r a -> Int)
-> (forall a. Eq a => a -> AnnotatedUpdateG b r a -> Bool)
-> (forall a. Ord a => AnnotatedUpdateG b r a -> a)
-> (forall a. Ord a => AnnotatedUpdateG b r a -> a)
-> (forall a. Num a => AnnotatedUpdateG b r a -> a)
-> (forall a. Num a => AnnotatedUpdateG b r a -> a)
-> Foldable (AnnotatedUpdateG b r)
forall a. Eq a => a -> AnnotatedUpdateG b r a -> Bool
forall a. Num a => AnnotatedUpdateG b r a -> a
forall a. Ord a => AnnotatedUpdateG b r a -> a
forall m. Monoid m => AnnotatedUpdateG b r m -> m
forall a. AnnotatedUpdateG b r a -> Bool
forall a. AnnotatedUpdateG b r a -> Int
forall a. AnnotatedUpdateG b r a -> [a]
forall a. (a -> a -> a) -> AnnotatedUpdateG b r a -> a
forall m a. Monoid m => (a -> m) -> AnnotatedUpdateG b r a -> m
forall b a. (b -> a -> b) -> b -> AnnotatedUpdateG b r a -> b
forall a b. (a -> b -> b) -> b -> AnnotatedUpdateG b r a -> b
forall (b :: BackendType) r a.
(Backend b, Eq a) =>
a -> AnnotatedUpdateG b r a -> Bool
forall (b :: BackendType) r a.
(Backend b, Num a) =>
AnnotatedUpdateG b r a -> a
forall (b :: BackendType) r a.
(Backend b, Ord a) =>
AnnotatedUpdateG b r a -> a
forall (b :: BackendType) r m.
(Backend b, Monoid m) =>
AnnotatedUpdateG b r m -> m
forall (b :: BackendType) r a.
Backend b =>
AnnotatedUpdateG b r a -> Bool
forall (b :: BackendType) r a.
Backend b =>
AnnotatedUpdateG b r a -> Int
forall (b :: BackendType) r a.
Backend b =>
AnnotatedUpdateG b r a -> [a]
forall (b :: BackendType) r a.
Backend b =>
(a -> a -> a) -> AnnotatedUpdateG b r a -> a
forall (b :: BackendType) r m a.
(Backend b, Monoid m) =>
(a -> m) -> AnnotatedUpdateG b r a -> m
forall (b :: BackendType) r b a.
Backend b =>
(b -> a -> b) -> b -> AnnotatedUpdateG b r a -> b
forall (b :: BackendType) r a b.
Backend b =>
(a -> b -> b) -> b -> AnnotatedUpdateG b r 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) r m.
(Backend b, Monoid m) =>
AnnotatedUpdateG b r m -> m
fold :: forall m. Monoid m => AnnotatedUpdateG b r m -> m
$cfoldMap :: forall (b :: BackendType) r m a.
(Backend b, Monoid m) =>
(a -> m) -> AnnotatedUpdateG b r a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> AnnotatedUpdateG b r a -> m
$cfoldMap' :: forall (b :: BackendType) r m a.
(Backend b, Monoid m) =>
(a -> m) -> AnnotatedUpdateG b r a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> AnnotatedUpdateG b r a -> m
$cfoldr :: forall (b :: BackendType) r a b.
Backend b =>
(a -> b -> b) -> b -> AnnotatedUpdateG b r a -> b
foldr :: forall a b. (a -> b -> b) -> b -> AnnotatedUpdateG b r a -> b
$cfoldr' :: forall (b :: BackendType) r a b.
Backend b =>
(a -> b -> b) -> b -> AnnotatedUpdateG b r a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> AnnotatedUpdateG b r a -> b
$cfoldl :: forall (b :: BackendType) r b a.
Backend b =>
(b -> a -> b) -> b -> AnnotatedUpdateG b r a -> b
foldl :: forall b a. (b -> a -> b) -> b -> AnnotatedUpdateG b r a -> b
$cfoldl' :: forall (b :: BackendType) r b a.
Backend b =>
(b -> a -> b) -> b -> AnnotatedUpdateG b r a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> AnnotatedUpdateG b r a -> b
$cfoldr1 :: forall (b :: BackendType) r a.
Backend b =>
(a -> a -> a) -> AnnotatedUpdateG b r a -> a
foldr1 :: forall a. (a -> a -> a) -> AnnotatedUpdateG b r a -> a
$cfoldl1 :: forall (b :: BackendType) r a.
Backend b =>
(a -> a -> a) -> AnnotatedUpdateG b r a -> a
foldl1 :: forall a. (a -> a -> a) -> AnnotatedUpdateG b r a -> a
$ctoList :: forall (b :: BackendType) r a.
Backend b =>
AnnotatedUpdateG b r a -> [a]
toList :: forall a. AnnotatedUpdateG b r a -> [a]
$cnull :: forall (b :: BackendType) r a.
Backend b =>
AnnotatedUpdateG b r a -> Bool
null :: forall a. AnnotatedUpdateG b r a -> Bool
$clength :: forall (b :: BackendType) r a.
Backend b =>
AnnotatedUpdateG b r a -> Int
length :: forall a. AnnotatedUpdateG b r a -> Int
$celem :: forall (b :: BackendType) r a.
(Backend b, Eq a) =>
a -> AnnotatedUpdateG b r a -> Bool
elem :: forall a. Eq a => a -> AnnotatedUpdateG b r a -> Bool
$cmaximum :: forall (b :: BackendType) r a.
(Backend b, Ord a) =>
AnnotatedUpdateG b r a -> a
maximum :: forall a. Ord a => AnnotatedUpdateG b r a -> a
$cminimum :: forall (b :: BackendType) r a.
(Backend b, Ord a) =>
AnnotatedUpdateG b r a -> a
minimum :: forall a. Ord a => AnnotatedUpdateG b r a -> a
$csum :: forall (b :: BackendType) r a.
(Backend b, Num a) =>
AnnotatedUpdateG b r a -> a
sum :: forall a. Num a => AnnotatedUpdateG b r a -> a
$cproduct :: forall (b :: BackendType) r a.
(Backend b, Num a) =>
AnnotatedUpdateG b r a -> a
product :: forall a. Num a => AnnotatedUpdateG b r a -> a
Foldable, Functor (AnnotatedUpdateG b r)
Foldable (AnnotatedUpdateG b r)
Functor (AnnotatedUpdateG b r)
-> Foldable (AnnotatedUpdateG b r)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> AnnotatedUpdateG b r a -> f (AnnotatedUpdateG b r b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    AnnotatedUpdateG b r (f a) -> f (AnnotatedUpdateG b r a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> AnnotatedUpdateG b r a -> m (AnnotatedUpdateG b r b))
-> (forall (m :: * -> *) a.
    Monad m =>
    AnnotatedUpdateG b r (m a) -> m (AnnotatedUpdateG b r a))
-> Traversable (AnnotatedUpdateG b r)
forall (b :: BackendType) r.
Backend b =>
Functor (AnnotatedUpdateG b r)
forall (b :: BackendType) r.
Backend b =>
Foldable (AnnotatedUpdateG b r)
forall (b :: BackendType) r (m :: * -> *) a.
(Backend b, Monad m) =>
AnnotatedUpdateG b r (m a) -> m (AnnotatedUpdateG b r a)
forall (b :: BackendType) r (f :: * -> *) a.
(Backend b, Applicative f) =>
AnnotatedUpdateG b r (f a) -> f (AnnotatedUpdateG b r a)
forall (b :: BackendType) r (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b) -> AnnotatedUpdateG b r a -> m (AnnotatedUpdateG b r b)
forall (b :: BackendType) r (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b) -> AnnotatedUpdateG b r a -> f (AnnotatedUpdateG b r 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 =>
AnnotatedUpdateG b r (m a) -> m (AnnotatedUpdateG b r a)
forall (f :: * -> *) a.
Applicative f =>
AnnotatedUpdateG b r (f a) -> f (AnnotatedUpdateG b r a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> AnnotatedUpdateG b r a -> m (AnnotatedUpdateG b r b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> AnnotatedUpdateG b r a -> f (AnnotatedUpdateG b r b)
$ctraverse :: forall (b :: BackendType) r (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b) -> AnnotatedUpdateG b r a -> f (AnnotatedUpdateG b r b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> AnnotatedUpdateG b r a -> f (AnnotatedUpdateG b r b)
$csequenceA :: forall (b :: BackendType) r (f :: * -> *) a.
(Backend b, Applicative f) =>
AnnotatedUpdateG b r (f a) -> f (AnnotatedUpdateG b r a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
AnnotatedUpdateG b r (f a) -> f (AnnotatedUpdateG b r a)
$cmapM :: forall (b :: BackendType) r (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b) -> AnnotatedUpdateG b r a -> m (AnnotatedUpdateG b r b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> AnnotatedUpdateG b r a -> m (AnnotatedUpdateG b r b)
$csequence :: forall (b :: BackendType) r (m :: * -> *) a.
(Backend b, Monad m) =>
AnnotatedUpdateG b r (m a) -> m (AnnotatedUpdateG b r a)
sequence :: forall (m :: * -> *) a.
Monad m =>
AnnotatedUpdateG b r (m a) -> m (AnnotatedUpdateG b r a)
Traversable)

deriving stock instance
  ( Backend b,
    Show v,
    Show r,
    Show (AnnBoolExp b v),
    Show (UpdateVariant b v),
    Show (MutationOutputG b r v)
  ) =>
  Show (AnnotatedUpdateG b r v)

deriving stock instance
  ( Backend b,
    Eq v,
    Eq r,
    Eq (AnnBoolExp b v),
    Eq (UpdateVariant b v),
    Eq (MutationOutputG b r v)
  ) =>
  Eq (AnnotatedUpdateG b r v)

type AnnotatedUpdate b = AnnotatedUpdateG b Void (SQLExpression b)

$(makeLenses ''AnnotatedUpdateG)