{-# LANGUAGE OverloadedStrings #-}

module Hydra.Sources.Tier0.Constraints where

-- Standard Tier-0 imports
import qualified Data.List             as L
import qualified Data.Map              as M
import qualified Data.Set              as S
import qualified Data.Maybe            as Y
import           Hydra.Dsl.Annotations
import           Hydra.Dsl.Bootstrap
import qualified Hydra.Dsl.Terms       as Terms
import           Hydra.Dsl.Types       as Types
import           Hydra.Sources.Core

import Hydra.Sources.Tier0.Query


hydraConstraintsModule :: Module
hydraConstraintsModule :: Module
hydraConstraintsModule = Namespace
-> [Element] -> [Module] -> [Module] -> Maybe String -> Module
Module Namespace
ns [Element]
elements [Module
hydraQueryModule] [Module
hydraCoreModule] (Maybe String -> Module) -> Maybe String -> Module
forall a b. (a -> b) -> a -> b
$
    String -> Maybe String
forall a. a -> Maybe a
Just String
"A model for path- and pattern-based graph constraints, which may be considered as part of the schema of a graph"
  where
    ns :: Namespace
ns = String -> Namespace
Namespace String
"hydra/constraints"
    core :: String -> Type
core = Namespace -> String -> Type
typeref (Namespace -> String -> Type) -> Namespace -> String -> Type
forall a b. (a -> b) -> a -> b
$ Module -> Namespace
moduleNamespace Module
hydraCoreModule
    query :: String -> Type
query = Namespace -> String -> Type
typeref (Namespace -> String -> Type) -> Namespace -> String -> Type
forall a b. (a -> b) -> a -> b
$ Module -> Namespace
moduleNamespace Module
hydraQueryModule
    constraints :: String -> Type
constraints = Namespace -> String -> Type
typeref Namespace
ns
    def :: String -> Type -> Element
def = Namespace -> String -> Type -> Element
datatype Namespace
ns

    elements :: [Element]
elements = [

      String -> Type -> Element
def String
"PathEquation" (Type -> Element) -> Type -> Element
forall a b. (a -> b) -> a -> b
$
        String -> Type -> Type
doc String
"A declared equivalence between two abstract paths in a graph" (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
        [FieldType] -> Type
record [
          String
"left"String -> Type -> FieldType
>: String -> Type
query String
"Path",
          String
"right"String -> Type -> FieldType
>: String -> Type
query String
"Path"],

      String -> Type -> Element
def String
"PatternImplication" (Type -> Element) -> Type -> Element
forall a b. (a -> b) -> a -> b
$
        String -> Type -> Type
doc String
"A pattern which, if it matches in a given graph, implies that another pattern must also match. Query variables are shared between the two patterns." (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
        [FieldType] -> Type
record [
          String
"antecedent"String -> Type -> FieldType
>: String -> Type
query String
"Pattern",
          String
"consequent"String -> Type -> FieldType
>: String -> Type
query String
"Pattern"]]