enum _PostOrdering {
  id_asc
  id_desc
  activityId_asc
  activityId_desc
  objectId_asc
  objectId_desc
  title_asc
  title_desc
  slug_asc
  slug_desc
  content_asc
  content_desc
  contentExcerpt_asc
  contentExcerpt_desc
  image_asc
  image_desc
  visibility_asc
  visibility_desc
  deleted_asc
  deleted_desc
  disabled_asc
  disabled_desc
  createdAt_asc
  createdAt_desc
  updatedAt_asc
  updatedAt_desc
  language_asc
  language_desc
  pinned_asc
  pinned_desc
}


type Post {
  id: ID!
  activityId: String
  objectId: String
  author: User @relation(name: "WROTE", direction: "IN")
  title: String!
  slug: String
  content: String!
  contentExcerpt: String
  image: String
  imageUpload: Upload
  visibility: Visibility
  deleted: Boolean
  disabled: Boolean
  pinned: Boolean
  disabledBy: User @relation(name: "DISABLED", direction: "IN")
  createdAt: String
  updatedAt: String
  language: String
  pinnedAt: String @cypher(
      statement: "MATCH (this)<-[pinned:PINNED]-(:User) WHERE NOT this.deleted = true AND NOT this.disabled = true RETURN pinned.createdAt"
    )
  pinnedBy: User @relation(name:"PINNED", direction: "IN")
  relatedContributions: [Post]!
    @cypher(
      statement: """
      MATCH (this)-[:TAGGED|CATEGORIZED]->(categoryOrTag)<-[:TAGGED|CATEGORIZED]-(post:Post)
      WHERE NOT post.deleted AND NOT post.disabled
      RETURN DISTINCT post
      LIMIT 10
      """
    )

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

  comments: [Comment]! @relation(name: "COMMENTS", direction: "IN")
  commentsCount: Int!
    @cypher(
      statement: "MATCH (this)<-[:COMMENTS]-(r:Comment) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)"
    )

  shoutedBy: [User]! @relation(name: "SHOUTED", direction: "IN")
  shoutedCount: Int!
    @cypher(
      statement: "MATCH (this)<-[:SHOUTED]-(r:User) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)"
    )
  
  # Has the currently logged in user shouted that post?
  shoutedByCurrentUser: Boolean!
    @cypher(
      statement: "MATCH (this)<-[:SHOUTED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1"
    )

  emotions: [EMOTED]
  emotionsCount: Int!
    @cypher(statement: "MATCH (this)<-[emoted:EMOTED]-(:User) RETURN COUNT(DISTINCT emoted)")
}

input _PostInput {
  id: ID!
}

type Mutation {
  CreatePost(
    id: ID
    title: String!
    slug: String
    content: String!
    image: String
    imageUpload: Upload
    visibility: Visibility
    language: String
    categoryIds: [ID]
    contentExcerpt: String
  ): Post
  UpdatePost(
    id: ID!
    title: String!
    slug: String
    content: String!
    contentExcerpt: String
    image: String
    imageUpload: Upload
    visibility: Visibility
    language: String
    categoryIds: [ID]
  ): Post
  DeletePost(id: ID!): Post
  AddPostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED
  RemovePostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED
  pinPost(id: ID!): Post
  unpinPost(id: ID!): Post
}

type Query {
  PostsEmotionsCountByEmotion(postId: ID!, data: _EMOTEDInput!): Int!
  PostsEmotionsByCurrentUser(postId: ID!): [String]
  profilePagePosts(filter: _PostFilter, first: Int, offset: Int, orderBy: [_PostOrdering]): [Post]
}
