<commit_before>#load "TestData.fsx"

open System
open Neo4jClient
open Neo4jClient.FsQuotations
open TestData

// Create client
let client = new GraphClient(new Uri("http://localhost:7474/db/data"), "neo4j", "<PASSWORD>");
do client.Connect()

// Init test data
do initTestData client

//let rec substituteExpr expression =
//    match expression with
//    | SpecificCall <@@ (=) @@> (_, _, exprList) ->
//        let lhs = substituteExpr exprList.Head
//        let rhs = substituteExpr exprList.Tail.Head
//        <@@ mul %%lhs %%rhs @@>
//    | ShapeVar var -> Expr.Var var
//    | ShapeLambda (var, expr) -> Expr.Lambda (var, substituteExpr expr)
//    | ShapeCombination(shapeComboObject, exprList) ->
//        RebuildShapeCombination(shapeComboObject, List.map substituteExpr exprList)


open FSharp.Linq.RuntimeHelpers.LeafExpressionConverter
open FSharp.Reflection
open FSharp.Quotations
open FSharp.Quotations.DerivedPatterns
open FSharp.Quotations.ExprShape
open FSharp.Quotations.Patterns
open FSharp.Linq.RuntimeHelpers
open System.Linq.Expressions
open Neo4jClient.Cypher

//<@
//where ((1 = 2 || 1 = 3) && 1 = 3)
//where (1 = 2 || 1 = 2 || 1 = 3)
//where (1 = 2 && 1 = 2 && 1 = 3)
//where (1 = 2 && 1 = 3)
//where (1 = 2)
//@>

<@
let u = declareNode<UserNode>
matchNode u
where (u.FacebookId > "12344" && u.FacebookId >= "12346")
returnResults u
@>
|> executeReadQuery client.Cypher

//<@
//let isResidentRel = declareRelationship<IsResidentOf>
//matchRightRelation declareNode<UserNode> isResidentRel declareNode<HouseholdNode>
//returnResults isResidentRel
//@>
//|> executeReadQuery client.Cypher
//
//<@
//let isResidentRel = declareRelationship<IsResidentOf>
//matchRightRelation declareNode<UserNode> isResidentRel declareNode<HouseholdNode>
//deleteRelationship isResidentRel
//@>
//|> executeWriteQuery client.Cypher<commit_msg>Update playground<commit_after>#load "TestData.fsx"

open System
open Neo4jClient
open Neo4jClient.FsQuotations
open TestData

#time "on"

// Create client
let client = new GraphClient(new Uri("http://localhost:7474/db/data"), "neo4j", "<PASSWORD>");
do client.Connect()

// Init test data
do initTestData client

open FSharp.Linq.RuntimeHelpers.LeafExpressionConverter
open FSharp.Reflection
open FSharp.Quotations
open FSharp.Quotations.DerivedPatterns
open FSharp.Quotations.ExprShape
open FSharp.Quotations.Patterns
open FSharp.Linq.RuntimeHelpers
open System.Linq.Expressions
open Neo4jClient.Cypher


let createNodeAndExecute (node: #INeo4jNode) =
    <@ createNode node @>
    |> executeWriteQuery client.Cypher

createNodeAndExecute { FacebookId = "Parisian" }

let cuir = { FacebookId = "Cuir" }
type MyNode =
    {
        Prop1: string
    }
    interface INeo4jNode

let node = { Prop1 = "abc" }
<@
mergeNode node
@>
|> executeWriteQuery client.Cypher

// Act
// TODO denisok: bug when value is propertyget
do
    let newHousehold: HouseholdNode = { Name = "<NAME>" }
    <@
        let parisian = declareNode<UserNode>
        matchNode parisian
        where (parisian.FacebookId = "Parisian")
        createRightRelation parisian declareRelationship<IsResidentOf> newHousehold
    @>
    |> executeWriteQuery client.Cypher

<@ let u = declareNode<UserNode>
   matchNode u
   returnResults u @>
|> executeReadQuery client.Cypher
|> Seq.toList

let query =
    <@
    let r = declareRelationship<IsResidentOf>
    matchLeftRelation declareNode<UserNode> r declareNode<HouseholdNode>
    returnResults r
    @>

let (Let(_, _, Sequential(m, _))) = query

open QuotationsHelpers

match m with
| IsMatchRelationClause(_) -> true
| _ -> false


let results =
    query
    |> executeReadQuery client.Cypher
    |> Seq.toArray


//let relationship = {  }
let denisRelationToColocDeLaJoie =
    <@
    let user = declareNode<UserNode>
    let house = declareNode<HouseholdNode>
    let rel = declareRelationship<IsResidentOf>
    matchRelation user rel house
    where (user.FacebookId = "Denis" && house.Name = "Coloc de la Joie")
    returnResults (user, rel, house)
    @>
    |> executeReadQuery client.Cypher
    |> Seq.toList

do
    let rel: IsResidentOf = { CustomHouseholdName = "Maison  Rpublique" }
    <@
    let user = declareNode<UserNode>
    let house = declareNode<HouseholdNode>
    matchNode user
    matchNode house
    where (user.FacebookId = "Denis" && house.Name = "Coloc de la Joie")
    mergeRightRelation user rel house
    @>
    |> executeWriteQuery client.Cypher

// TODO denisok: shouldn't allow relationship creation if no default constructor - except if nullable
client
    .Cypher
    .Match("(user: UserNode)")
    .Match("(house: HouseholdNode)")
    .Where(fun (user: UserNode) -> user.FacebookId = "Denis")
    .AndWhere(fun (house: HouseholdNode) -> house.Name = "Coloc de la Joie")
    .Merge("(user)-[r:IsResidentOf]->(house)")
    .OnCreate()
    .Set("r = {myParam}")
    .WithParam("myParam", { CustomHouseholdName = "Maison  Rpublique" })
    .ExecuteWithoutResults()
{'fraction_non_alphanumeric': 0.12045043233460688, 'fraction_numerical': 0.01085863663784436, 'mean_word_length': 3.8104448742746615, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7383253', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1644, 'n_words': 394}