type Query {
    "The current user logged in the API."
    viewer: User!
    "Get the data from a course on the platform."
    course(itemId: ItemIdInput!): Course
    "Get the data from a session on the platform."
    session(itemId: ItemIdInput!): Session
    "Get the data from a session category."
    sessionCategory(id: Int!): SessionCategory
}

type Mutation {
    "Authenticate user."
    authenticate(username: String!, password: String!): AuthenticatePayload!
    "Send messages to user contacts."
    viewerSendMessage(
        "Unique IDs of users who will receive the message."
        receivers: [Int!]!,
        subject: String!,
        content: String!
    ): [ViewerSendMessagePayload!]
    addForumThread(
        thread: AddForumThreadInput!,
        course: Int!,
        session: Int! = 0
    ): CourseForumThread!
    addForumPost(
        post: AddForumPostInput!,
        "Course ID"
        course: Int!,
        "Session ID"
        session: Int! = 0
    ): CourseForumPost!
    addCourseNote(
        note: AddCourseNoteInput!,
        "Course ID"
        course: Int!,
        "Session ID"
        session: Int! = 0
    ): CourseNote!
    createCourse(course: CreateCourseInput!, itemId: ItemIdInput!): Course
    createUser(user: CreateUserInput!, itemId: ItemIdInput!): User
    subscribeUserToCourse(
        user: Int!
        course: Int!
    ): Boolean
    disableUser(itemId: ItemIdInput!): Boolean
    enableUser(itemId: ItemIdInput!): Boolean
    deleteUser(itemId: ItemIdInput!): Boolean
    editUser(user: EditUserInput!, itemId: ItemIdInput!): User
    editCourse(course: EditCourseInput!, itemId: ItemIdInput!): Course
    deleteCourse(itemId: ItemIdInput!): Boolean
}

# Objects

type AuthenticatePayload {
    "Authorization token."
    token: String!
    "ID for the URL"
    urlId: Int!
}

"The status for each message in queue."
type ViewerSendMessagePayload {
    "The unique ID for the receiver user."
    receiverId: Int!
    "It indicates if the message was or wasn't sent."
    sent: Boolean!
}

"A registered user on the platform."
type User {
    "The unique ID of the user."
    id: Int
    firstname: String
    lastname: String
    username: String
    email: String
    officialCode: String
    status: UserStatus
    picture(size: ImageSize = ICON_SIZE_SMALL): String
    "Received messages for the user."
    messages(
        "Last received by the app message ID."
        lastId: Int = 0
    ): [UserMessage!]
    "Get potential users to send a message for the current user."
    messageContacts(
        "The search text to filter the user list."
        filter: String!
    ): [User!]
    "Course list for the current user."
    courses: [Course!]
    "Session list for the current user."
    sessions: [Session!]
}

"Received message by user."
type UserMessage {
    "The unique ID of the message."
    id: Int
    title: String
    content: String
    sender: User!
    sendDate: DateTime
    excerpt(
        "The approximate desired length. 50 chars by default."
        length: Int = 50
    ): String
    hasAttachments: Boolean
}

"A course registered on the platform."
type Course {
    "The unique ID of the course."
    id: Int
    title: String
    code: String!
    categoryCode: String
    directory: String
    picture(
        "It indicates whether to get the full-sized image."
        fullSize: Boolean = false
    ): String
    "Teachers list in course. Or tutors list from course in session."
    teachers: [User!]
    "List of available tools for student view."
    tools(
        "Filter by one type of tool"
        type: CourseToolType
    ): [CourseTool!]
}

"Global summary of the course."
type ToolDescription implements CourseTool {
    name: String
    category: String
    image: String
    customIcon: String
    descriptions: [CourseDescription!]
}

"A section for the course description."
type CourseDescription {
    id: Int
    title: String
    content: String
    descriptionType: Int
}

"Personal notes relevant to student or coursework."
type ToolNotebook implements CourseTool {
    name: String
    category: String
    image: String
    customIcon: String
    notes: [CourseNote!]
}

"Note by user in notebook tool."
type CourseNote {
    id: Int
    title: String
    description: String
    creationDate: DateTime
    updateDate: DateTime
    status: Int
}

"Announcements related to the course."
type ToolAnnouncements implements CourseTool {
    name: String
    category: String
    image: String
    customIcon: String
    announcements: [CourseAnnouncement!]
    announcement(id: Int!): CourseAnnouncement
}

"A course announcement."
type CourseAnnouncement {
    id: Int
    title: String
    content: String
    author: User!
    lastUpdateDate: DateTime
}

"Course forum tool."
type ToolForums implements CourseTool {
    name: String
    category: String
    image: String
    customIcon: String
    categories: [CourseForumCategory!]
    forum(id: Int!): CourseForum
    thread(id: Int!): CourseForumThread
}

type CourseForumCategory {
    id: Int
    title: String
    comment: String
    locked: Int
    forums: [CourseForum!]
}

type CourseForum {
    id: Int
    title: String
    comment: String
    image: String
    numberOfThreads: Int
    numberOfPosts: Int
    threads: [CourseForumThread!]
}

type CourseForumThread {
    id: Int
    title: String
    userPoster: User
    date: DateTime
    sticky: Boolean
    locked: Int
    numberOfViews: Int
    numberOfReplies: Int
    closeDate: DateTime
    posts: [CourseForumPost!]
}

type CourseForumPost {
    id: Int
    title: String
    text: String
    userPoster: User
    date: DateTime
    parent: CourseForumPost
    visible: Boolean
    status: Int
}

"A comprehensive diary/calendar tool"
type ToolAgenda implements CourseTool {
    name: String
    category: String
    image: String
    customIcon: String
    events: [CourseAgendaEvent!]
}

type CourseAgendaEvent {
    id: Int
    className: String
    title: String
    description: String
    startDate: DateTime
    endDate: DateTime
    allDay: Boolean
    borderColor: String
    backgroundColor: String
}

type ToolDocuments implements CourseTool {
    name: String
    category: String
    image: String
    customIcon: String
    documents(dirId: Int): [CourseDocument!]
}

type CourseDocument {
  id: Int
  fileType: String
  title: String
  comment: String
  path: String
  icon: String
  size: String
  url: String
}

"A specific sequence of learning objects/experiences."
type ToolLearningPath implements CourseTool {
    name: String
    category: String
    image: String
    customIcon: String
    categories: [CourseLearnpathCategory!]
}

type CourseLearnpathCategory {
    id: Int
    name: String
    learnpaths: [CourseLearnpath!]
}

type CourseLearnpath {
    id: Int
    title: String
    progress: Int
    url: String
}

"A session registered on the platform."
type Session {
    "The unique ID of the session."
    id: Int
    name: String
    category: SessionCategory
    description: String
    numberOfCourses: Int
    numberOfUsers: Int
    duration: Int
    displayStartDate: DateTime
    displayEndDate: DateTime
    accessStartDate: DateTime
    accessEndDate: DateTime
    coachAccessStartDate: DateTime
    coachAccessEndDate: DateTime
    generalCoach: User!
    courses: [Course!]
}

"A session category."
type SessionCategory {
    "The unique ID of the category."
    id: Int
    name: String
    startDate: DateTime
    endDate: DateTime
}

# Interfaces

interface CourseTool {
  name: String
  category: String
  image: String
  customIcon: String
}

# Enums

"One of the statuses for the user."
enum UserStatus {
    "Global status of a user: Course Manager."
    TEACHER
    "Global status of a user: Session Admin."
    SESSION_ADMIN
    "Global status of a user: Human Ressource Manager."
    DRH
    "Global status of a user: Student."
    STUDENT
}

"One of the sizes for the picture."
enum ImageSize {
    "Image in small size: 16px."
    ICON_SIZE_TINY
    "Image in small size: 22px."
    ICON_SIZE_SMALL
    "Image in small size: 32px."
    ICON_SIZE_MEDIUM
    "Image in small size: 48px."
    ICON_SIZE_LARGE
    "Image in small size: 64px."
    ICON_SIZE_BIG
    "Image in small size: 128px."
    ICON_SIZE_HUGE
}

"One of the types of course tool"
enum CourseToolType {
    TOOL_COURSE_DESCRIPTION
    TOOL_ANNOUNCEMENT
    TOOL_NOTEBOOK
    TOOL_FORUM
    TOOL_CALENDAR_EVENT
    TOOL_DOCUMENT
    TOOL_LEARNPATH
}

"One of visibility of thhe course"
enum CourseVisibility {
    COURSE_VISIBILITY_OPEN_WORLD
    COURSE_VISIBILITY_OPEN_PLATFORM
    COURSE_VISIBILITY_REGISTERED
    COURSE_VISIBILITY_CLOSED
    COURSE_VISIBILITY_HIDDEN
}

# Inputs

input CreateCourseInput {
    title: String!,
    categoryCode: String,
    wantedCode: String,
    language: String = "en",
    diskQuota: Int = 100,
    visibility: CourseVisibility,
    allowSubscription: Boolean = true,
    allowUnsubscription: Boolean = false
}

input EditCourseInput {
    title: String,
    categoryCode: String,
    visualCode: String,
    language: String = "en",
    diskQuota: Int = 100,
    visibility: CourseVisibility,
    allowSubscription: Boolean = true,
    allowUnsubscription: Boolean = false
}

input CreateUserInput {
    firstname: String!,
    lastname: String!,
    status: UserStatus!,
    email: String!,
    username: String!,
    password: String!,
    isActive: Boolean = true,
    language: String,
    phone: String,
    expirationDate: DateTime
}

input AddForumThreadInput {
    "Forum ID in which the tread will be created"
    forum: Int = 0,
    title: String!,
    text: String!,
    "Send a notification when adding"
    notify: Boolean! = true
}

input AddForumPostInput {
    "Forum ID in which the post will be created"
    forum: Int = 0,
    "Thread ID in which the post will be created"
    thread: Int = 0,
    "Post parent ID that is answered"
    parent: Int = 0,
    title: String!,
    text: String!,
    "Send a notification when adding"
    notify: Boolean! = true
}

input AddCourseNoteInput {
    title: String!,
    text: String!
}

input ItemIdInput {
    name: String!
    value: String!
}

input EditUserInput {
    firstname: String,
    lastname: String,
    status: UserStatus,
    email: String,
    username: String,
    officialCode: String,
    isActive: Boolean,
    language: String,
    phone: String,
    expirationDate: DateTime
}

# Scalars

scalar DateTime
