package com.bio4j.angulillos.test;

import java.util.stream.Stream;
import java.util.Optional;
import java.util.Date;
import java.net.URL;

import com.bio4j.angulillos.*;

public abstract class TwitterGraphTestSuite<RV,RE> {

  protected Twitter<RV,RE> g;

  //////////////////////////////////////////

  // Trying to use some API and see that it returns correct type without any conversions:
  public final Twitter<RV,RE>.User u =
    g.user.fromRaw(null)
      .set(g.user.name, "Bob")
      .set(g.user.age, 42);

  public final String name = u.get(g.user.name);

  public final Twitter<RV,RE>.Tweet t =
    g.tweet.fromRaw(null)
      .set(g.tweet.text, "blah-bluh");

  //////////////////////////////////////////

  // Examples with edges:

  public final Twitter<RV,RE>.Posted p =
    g.posted.fromRaw(null)
      .set(g.posted.when, null);

  public final Twitter<RV,RE>.User poster = p.source();


  public final Stream<Twitter<RV,RE>.Follows> fe = u.outE(g.follows);

  public final Stream<Date> dates = fe.map(edge -> edge.get(g.follows.since));


  public final Stream<Twitter<RV,RE>.Tweet> ts = u.outV(g.posted);

  public final Stream<String> texts = ts.map(tweet -> tweet.get(g.tweet.text));

  public final Optional<Twitter<RV,RE>.Tweet> fromURL(URL url) { return g.tweet.byUrl.find(url); }

  // to print the schema:

  // g.vertexTypes.foreach { vt =>
  //   println(s"""${vt._label}:
  //     |  properties: ${vt.properties().map(_._label())}
  //     |  inEdges: ${vt.inEdges().map{ _._label() }}
  //     |  outEdges: ${vt.outEdges().map{ _._label() }}""".stripMargin
  //     )
  // }
  //
  // g.edgeTypes.foreach { et =>
  //   println(s"""${et._label}:
  //     |  properties: ${et.properties().map(_._label())}
  //     |  source: ${et.source()._label()}
  //     |  target: ${et.target()._label()}""".stripMargin
  //     )
  // }

  // public void doSomething(Twitter<RV,RE>.User user) {
  //
  //   Stream<Twitter<RV,RE>.Tweet> tweets = user.outV(g.posted);
  // }
  //
  // public Stream<Twitter<RV,RE>.User> tweetedTheTweetsThatTweeted(Twitter<RV,RE>.User user) {
  //
  //   return user.outV(g.posted).flatMap(
  //     tw -> tw.inV(g.posted)
  //   );
  // }
  //

  // see #78
  /* This uses arity-specific methods to return **the** user that tweeted a tweet. */
  public Twitter<RV,RE>.User tweeted(Twitter<RV,RE>.Tweet tweet) {

    return tweet.inOneV(g.posted);
  }
  //
  // public Stream<Twitter<RV,RE>.User> repliedToSomeTweetFrom(Twitter<RV,RE>.User user) {
  //
  //   return user
  //     .outV( g.posted )
  //     .flatMap( tw -> tw.inV( g.RepliesTo() ) )
  //     .map( tw -> tw.inOneV( g.posted ) )
  //     .distinct();
  // }
}

@@ -738,17 +738,16 @@
  edges:%0A
-%0A
   public
@@ -893,25 +893,24 @@
 .source();%0A%0A
-%0A
   public fin
@@ -1048,17 +1048,16 @@
 nce));%0A%0A
-%0A
   public
@@ -1302,702 +1302,8 @@
 %7D%0A%0A 
- // to print the schema:%0A%0A  // g.vertexTypes.foreach %7B vt =%3E%0A  //   println(s%22%22%22$%7Bvt._label%7D:%0A  //     %7C  properties: $%7Bvt.properties().map(_._label())%7D%0A  //     %7C  inEdges: $%7Bvt.inEdges().map%7B _._label() %7D%7D%0A  //     %7C  outEdges: $%7Bvt.outEdges().map%7B _._label() %7D%7D%22%22%22.stripMargin%0A  //     )%0A  // %7D%0A  //%0A  // g.edgeTypes.foreach %7B et =%3E%0A  //   println(s%22%22%22$%7Bet._label%7D:%0A  //     %7C  properties: $%7Bet.properties().map(_._label())%7D%0A  //     %7C  source: $%7Bet.source()._label()%7D%0A  //     %7C  target: $%7Bet.target()._label()%7D%22%22%22.stripMargin%0A  //     )%0A  // %7D%0A%0A  // public void doSomething(Twitter%3CRV,RE%3E.User user) %7B%0A  //%0A  //   Stream%3CTwitter%3CRV,RE%3E.Tweet%3E tweets = user.outV(g.posted);%0A  // %7D%0A  //%0A  //
  pub
@@ -1386,33 +1386,26 @@
 ser user) %7B%0A
+%0A
  
- //%0A  //
    return us
@@ -1432,19 +1432,16 @@
 atMap(%0A 
- //
      tw 
@@ -1465,19 +1465,16 @@
 d)%0A 
- //
    );%0A  
 // %7D
@@ -1473,31 +1473,10 @@
 ;%0A  
-// %7D%0A  //%0A%0A  // see #78
+%7D%0A
 %0A  /
@@ -1669,278 +1669,6 @@
   %7D%0A
-  //%0A  // public Stream%3CTwitter%3CRV,RE%3E.User%3E repliedToSomeTweetFrom(Twitter%3CRV,RE%3E.User user) %7B%0A  //%0A  //   return user%0A  //     .outV( g.posted )%0A  //     .flatMap( tw -%3E tw.inV( g.RepliesTo() ) )%0A  //     .map( tw -%3E tw.inOneV( g.posted ) )%0A  //     .distinct();%0A  // %7D%0A
 %7D%0A

clean the sample test a bit