"A datetime string with format `Y-m-d H:i:s`, e.g. `2018-05-23 13:43:32`."
scalar DateTime @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime")

"scalar Upload"
scalar Upload @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Upload")

extend type Query{
    "Paginate posts"
    posts: [Post!]! @paginate @guard

    "Post by Id"
    post(id: Int! @eq): Post @find @guard

    "Post By Auth User"
    postsByAuthUser: [Post!]! @all @whereAuth(relation: "author") @guard

    "Post Popular ordered by field views postPopulars: [Post!]! @all @orderBy(column: 'views', direction: DESC) @guard"
    postPopulars(query: String): [Post!]! @guard @paginate(builder: "App\\GraphQL\\Queries\\PostPopulars")

    "FULLTEXT Search"
    textSearchPosts(query: String!): [Post!]! @guard

    "Filter Post"
    #postsFilters(orderBy: _ @orderBy(columns: ["created_at", "id"])): [Post!]! @paginate @guard
    postsFilters(column:String!,order: String!):[Post!]! @guard @paginate(builder: "App\\GraphQL\\Queries\\PostsFilters")
}

extend type Mutation{
   createPost(title: String!, description: String, content: String!, user_id: ID!, purchase_id: ID, latitude: Float!, longitude: Float!, address: String): Post! @guard
   
   updatePost(post_id:ID!, title: String!, description: String, content: String!, purchase_id: ID, latitude: Float!, longitude: Float!, address: String!): Post @guard

   uploadImagePost(files: [Upload!]!, post_id:ID!): String!

   uploadVideoPost(files: [Upload!]!, post_id:ID!): String!

   deleteImagePost(image_id: ID!): String!

   deletePost(id: ID!): [String!]! @guard
   
   likePost(user_id: ID!, post_id: ID!): String!
   
   disLikePost(user_id: ID!, post_id: ID!): String!
   
   createComment(user_id: ID!, post_id: ID!, comment: String!): [String!]!
}

type Liked {
    rendered: String!
}

type Category {
    id: ID!

    name: String!

    description: String
}

type Comment {
    id: ID!
    user_id: ID!
    post_id: ID!
    comment: String!

    user: User @hasOne
}

type ImagePost {
    id: ID!

    name: String!

    path: String!
}

type PostVideo {
    id: ID!

    name: String!

    path: String!
}

type Post {
    "Unique primary key."
    id: ID!

    "Title of post."
    title: String!

    "Description of post (optional)."
    description: String

    likeCount: Int! @method(name: "likeCount")

    commentCount: Int! @count(relation: "comments")

    "Content of the post."
    content: String!

    liked: Boolean @method(name: "liked")

    "Quantoty of views of the post."
    views: Int

    "User author of post."
    user_id: ID!

    "When the account was created."
    created_at: DateTime!

    "When the account was last updated."
    updated_at: DateTime!

    author: User! @belongsTo

    categories: [Category!] @belongsTo

    comments: [Comment] @hasMany

    images: [ImagePost!] @hasMany

    videos: [PostVideo!] @hasMany

    purchase_id: ID

    longitude: Float!

    latitude: Float!

    address: String
}