type User {
  id: ID!
  actorId: String
  name: String
  email: String! @cypher(statement: "MATCH (this)-[: PRIMARY_EMAIL]->(e: EmailAddress) RETURN e.email")
  slug: String!
  avatar: String
  coverImg: String
  deleted: Boolean
  disabled: Boolean
  disabledBy: User @relation(name: "DISABLED", direction: "IN")
  role: UserGroup!
  publicKey: String
  invitedBy: User @relation(name: "INVITED", direction: "IN")
  invited: [User] @relation(name: "INVITED", direction: "OUT")

  location: Location @cypher(statement: "MATCH (this)-[: IS_IN]->(l: Location) RETURN l")
  locationName: String
  about: String
  socialMedia: [SocialMedia]! @relation(name: "OWNED_BY", direction: "IN")

  # createdAt: DateTime
  # updatedAt: DateTime
  createdAt: String
  updatedAt: String

  termsAndConditionsAgreedVersion: String
  termsAndConditionsAgreedAt: String

  allowEmbedIframes: Boolean
  locale: String
  friends: [User]! @relation(name: "FRIENDS", direction: "BOTH")
  friendsCount: Int! @cypher(statement: "MATCH (this)<-[: FRIENDS]->(r: User) RETURN COUNT(DISTINCT r)")

  following: [User]! @relation(name: "FOLLOWS", direction: "OUT")
  followingCount: Int! @cypher(statement: "MATCH (this)-[: FOLLOWS]->(r: User) RETURN COUNT(DISTINCT r)")

  followedBy: [User]! @relation(name: "FOLLOWS", direction: "IN")
  followedByCount: Int! @cypher(statement: "MATCH (this)<-[: FOLLOWS]-(r: User) RETURN COUNT(DISTINCT r)")

  # Is the currently logged in user following that user?
  followedByCurrentUser: Boolean! @cypher(
  statement: """
  MATCH (this)<-[: FOLLOWS]-(u: User { id: $cypherParams.currentUserId})
  RETURN COUNT(u) >= 1
  """
  )
  isBlocked: Boolean! @cypher(
  statement: """
  MATCH (this)<-[: BLOCKED]-(u: User { id: $cypherParams.currentUserId})
  RETURN COUNT(u) >= 1
  """
  )

  # contributions: [WrittenPost]!
  # contributions2(first: Int = 10, offset: Int = 0): [WrittenPost2]!
  # @cypher(
  # statement: "MATCH (this)-[w:WROTE]->(p:Post) RETURN p as Post, w.timestamp as timestamp"
  # )
  contributions: [Post]! @relation(name: "WROTE", direction: "OUT")
  contributionsCount: Int! @cypher(
  statement: """
  MATCH (this)-[: WROTE]->(r: Post)
  WHERE NOT r.deleted = true AND NOT r.disabled = true
  RETURN COUNT(r)
  """
  )

  comments: [Comment]! @relation(name: "WROTE", direction: "OUT")
  commentedCount: Int! @cypher(statement: "MATCH (this)-[: WROTE]->(: Comment)-[: COMMENTS]->(p: Post) WHERE NOT p.deleted = true AND NOT p.disabled = true RETURN COUNT(DISTINCT(p))")

  shouted: [Post]! @relation(name: "SHOUTED", direction: "OUT")
  shoutedCount: Int! @cypher(statement: "MATCH (this)-[: SHOUTED]->(r: Post) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)")

  categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT")

  badges: [Badge]! @relation(name: "REWARDED", direction: "IN")
  badgesCount: Int! @cypher(statement: "MATCH (this)<-[: REWARDED]-(r: Badge) RETURN COUNT(r)")

  emotions: [EMOTED]
}


input _UserFilter {
  AND: [_UserFilter!]
  OR: [_UserFilter!]
  name_contains: String
  about_contains: String
  slug_contains: String
  id: ID
  id_not: ID
  id_in: [ID!]
  id_not_in: [ID!]
  id_contains: ID
  id_not_contains: ID
  id_starts_with: ID
  id_not_starts_with: ID
  id_ends_with: ID
  id_not_ends_with: ID
  friends: _UserFilter
  friends_not: _UserFilter
  friends_in: [_UserFilter!]
  friends_not_in: [_UserFilter!]
  friends_some: _UserFilter
  friends_none: _UserFilter
  friends_single: _UserFilter
  friends_every: _UserFilter
  following: _UserFilter
  following_not: _UserFilter
  following_in: [_UserFilter!]
  following_not_in: [_UserFilter!]
  following_some: _UserFilter
  following_none: _UserFilter
  following_single: _UserFilter
  following_every: _UserFilter
  followedBy: _UserFilter
  followedBy_not: _UserFilter
  followedBy_in: [_UserFilter!]
  followedBy_not_in: [_UserFilter!]
  followedBy_some: _UserFilter
  followedBy_none: _UserFilter
  followedBy_single: _UserFilter
  followedBy_every: _UserFilter
  role_in: [UserGroup!]
}

type Query {
  User(
  id: ID
  email: String
  actorId: String
  name: String
  slug: String
  avatar: String
  coverImg: String
  role: UserGroup
  locationName: String
  about: String
  createdAt: String
  updatedAt: String
  friendsCount: Int
  followingCount: Int
  followedByCount: Int
  followedByCurrentUser: Boolean
  contributionsCount: Int
  commentedCount: Int
  shoutedCount: Int
  badgesCount: Int
  first: Int
  offset: Int
  orderBy: [_UserOrdering]
  filter: _UserFilter
  ): [User]

  blockedUsers: [User]
  currentUser: User
}

type Mutation {
  UpdateUser (
  id: ID!
  name: String
  email: String
  slug: String
  avatar: String
  coverImg: String
  avatarUpload: Upload
  locationName: String
  about: String
  termsAndConditionsAgreedVersion: String
  termsAndConditionsAgreedAt: String
  allowEmbedIframes: Boolean
	locale: String
  ): User

  DeleteUser(id: ID!, resource: [Deletable]): User


  block(id: ID!): User
  unblock(id: ID!): User
}
