module Database.Bolt.Extras.DSL.Internal.Language
  (
    CypherDSL
  , createF
  , matchF
  , optionalMatchF
  , mergeF
  , whereF
  , setF
  , deleteF
  , detachDeleteF
  , removeF
  , returnF
  , withF
  , textF
  ) where

import           Control.Monad.Free                      (Free (..), liftF)
import           Data.Text                               (Text)
import           Database.Bolt.Extras.DSL.Internal.Types (Conds (..), Expr (..),
                                                          Selectors)

-- | A synonym for 'Free' DSL.
--
type CypherDSL a = Free Expr a

-- | Prepare 'CREATE' query
--
createF :: Selectors -> Free Expr ()
createF :: Selectors -> Free Expr ()
createF Selectors
sels = Expr () -> Free Expr ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (Selectors -> () -> Expr ()
forall next. Selectors -> next -> Expr next
Create Selectors
sels ())

-- | Prepare 'MATCH' query
--
matchF :: Selectors -> Free Expr ()
matchF :: Selectors -> Free Expr ()
matchF Selectors
sels = Expr () -> Free Expr ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (Selectors -> () -> Expr ()
forall next. Selectors -> next -> Expr next
Match Selectors
sels ())

-- | Prepare 'OPTIONAL MATCH' query
--
optionalMatchF :: Selectors -> Free Expr ()
optionalMatchF :: Selectors -> Free Expr ()
optionalMatchF Selectors
sels = Expr () -> Free Expr ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (Selectors -> () -> Expr ()
forall next. Selectors -> next -> Expr next
OptionalMatch Selectors
sels ())

-- | Prepare 'MERGE' query
--
mergeF :: Selectors -> Free Expr ()
mergeF :: Selectors -> Free Expr ()
mergeF Selectors
sels = Expr () -> Free Expr ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (Selectors -> () -> Expr ()
forall next. Selectors -> next -> Expr next
Merge Selectors
sels ())

-- | Prepare 'WHERE' query
--
whereF :: Conds -> Free Expr ()
whereF :: Conds -> Free Expr ()
whereF Conds
conds = Expr () -> Free Expr ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (Conds -> () -> Expr ()
forall next. Conds -> next -> Expr next
Where Conds
conds ())

-- | Prepare 'SET' query
--
setF :: [Text] -> Free Expr ()
setF :: [Text] -> Free Expr ()
setF [Text]
txts = Expr () -> Free Expr ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ([Text] -> () -> Expr ()
forall next. [Text] -> next -> Expr next
Set [Text]
txts ())

-- | Prepare 'DELETE' query
--
deleteF :: [Text] -> Free Expr ()
deleteF :: [Text] -> Free Expr ()
deleteF [Text]
txts = Expr () -> Free Expr ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ([Text] -> () -> Expr ()
forall next. [Text] -> next -> Expr next
Delete [Text]
txts ())

-- | Prepare 'DETACH DELETE' query
--
detachDeleteF :: [Text] -> Free Expr ()
detachDeleteF :: [Text] -> Free Expr ()
detachDeleteF [Text]
txts = Expr () -> Free Expr ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ([Text] -> () -> Expr ()
forall next. [Text] -> next -> Expr next
DetachDelete [Text]
txts ())

-- | Prepare 'REMOVE' query
--
removeF :: [Text] -> Free Expr ()
removeF :: [Text] -> Free Expr ()
removeF [Text]
txts = Expr () -> Free Expr ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ([Text] -> () -> Expr ()
forall next. [Text] -> next -> Expr next
Remove [Text]
txts ())

-- | Prepare 'RETURN' query
--
returnF :: [Text] -> Free Expr ()
returnF :: [Text] -> Free Expr ()
returnF [Text]
txts = Expr () -> Free Expr ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ([Text] -> () -> Expr ()
forall next. [Text] -> next -> Expr next
Return [Text]
txts ())

-- | Prepare 'WITH' query
--
withF :: [Text] -> Free Expr ()
withF :: [Text] -> Free Expr ()
withF [Text]
txts = Expr () -> Free Expr ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF ([Text] -> () -> Expr ()
forall next. [Text] -> next -> Expr next
With [Text]
txts ())

-- | Prepare query with custom text
--
textF :: Text -> Free Expr ()
textF :: Text -> Free Expr ()
textF Text
txt = Expr () -> Free Expr ()
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (Text -> () -> Expr ()
forall next. Text -> next -> Expr next
Text Text
txt ())