
type TaskLabel {
  id: ID!
  projectLabel: ProjectLabel!
  assignedDate: Time!
}

type ChecklistBadge {
  complete: Int!
  total: Int!
}

type CommentsBadge {
  total: Int!
  unread: Boolean!
}

type TaskBadges {
  checklist: ChecklistBadge
  comments: CommentsBadge
}

type Task {
  id: ID!
  taskGroup: TaskGroup!
  createdAt: Time!
  name: String!
  position: Float!
  description: String
  watched: Boolean!
  dueDate: Time
  hasTime: Boolean!
  complete: Boolean!
  completedAt: Time
  assigned: [Member!]!
  labels: [TaskLabel!]!
  checklists: [TaskChecklist!]!
  badges: TaskBadges!
  activity: [TaskActivity!]!
  comments: [TaskComment!]!
}

type TaskActivityData {
  name: String!
  value: String!
}

enum ActivityType {
  TASK_ADDED
  TASK_MOVED
  TASK_MARKED_COMPLETE
  TASK_MARKED_INCOMPLETE
  TASK_DUE_DATE_CHANGED
  TASK_DUE_DATE_ADDED
  TASK_DUE_DATE_REMOVED
  TASK_CHECKLIST_CHANGED
  TASK_CHECKLIST_ADDED
  TASK_CHECKLIST_REMOVED
}

type TaskActivity {
  id: ID!
  type: ActivityType!
  data: [TaskActivityData!]!
  causedBy: CausedBy!
  createdAt: Time!
}

type CausedBy {
  id: ID!
  fullName: String!
  profileIcon: ProfileIcon
}


type CreatedBy {
  id: ID!
  fullName: String!
  profileIcon: ProfileIcon!
}

type TaskComment {
  id: ID!
  createdAt: Time!
  updatedAt: Time
  message: String!
  createdBy: CreatedBy!
  pinned: Boolean!
}

type TaskChecklistItem {
  id: ID!
  name: String!
  taskChecklistID: UUID!
  complete: Boolean!
  position: Float!
  dueDate: Time!
}

type TaskChecklist {
  id: ID!
  name: String!
  position: Float!
  items: [TaskChecklistItem!]!
}

extend type Mutation {
  createTaskChecklist(input: CreateTaskChecklist!):
    TaskChecklist! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
  deleteTaskChecklist(input: DeleteTaskChecklist!):
    DeleteTaskChecklistPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_CHECKLIST)
  updateTaskChecklistName(input: UpdateTaskChecklistName!):
    TaskChecklist! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_CHECKLIST)
  createTaskChecklistItem(input: CreateTaskChecklistItem!):
    TaskChecklistItem! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_CHECKLIST)
  updateTaskChecklistLocation(input: UpdateTaskChecklistLocation!):
    UpdateTaskChecklistLocationPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_CHECKLIST)

  updateTaskChecklistItemName(input: UpdateTaskChecklistItemName!):
    TaskChecklistItem! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_CHECKLIST_ITEM)
  setTaskChecklistItemComplete(input: SetTaskChecklistItemComplete!):
    TaskChecklistItem! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_CHECKLIST_ITEM)
  deleteTaskChecklistItem(input: DeleteTaskChecklistItem!):
    DeleteTaskChecklistItemPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_CHECKLIST_ITEM)
  updateTaskChecklistItemLocation(input: UpdateTaskChecklistItemLocation!):
    UpdateTaskChecklistItemLocationPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_CHECKLIST_ITEM)

}

input UpdateTaskChecklistItemLocation {
  taskChecklistID: UUID!
  taskChecklistItemID: UUID!
  position: Float!
}

type UpdateTaskChecklistItemLocationPayload {
  taskChecklistID: UUID!
  prevChecklistID: UUID!
  checklistItem: TaskChecklistItem!
}

input UpdateTaskChecklistLocation {
  taskChecklistID: UUID!
  position: Float!
}

type UpdateTaskChecklistLocationPayload {
  checklist: TaskChecklist!
}

input CreateTaskChecklist {
  taskID: UUID!
  name: String!
  position: Float!
}

type DeleteTaskChecklistItemPayload {
  ok: Boolean!
  taskChecklistItem: TaskChecklistItem!
}

input CreateTaskChecklistItem {
  taskChecklistID: UUID!
  name: String!
  position: Float!
}

input SetTaskChecklistItemComplete {
  taskChecklistItemID: UUID!
  complete: Boolean!
}

input DeleteTaskChecklistItem {
  taskChecklistItemID: UUID!
}

input UpdateTaskChecklistItemName {
  taskChecklistItemID: UUID!
  name: String!
}

input UpdateTaskChecklistName {
  taskChecklistID: UUID!
  name: String!
}
input DeleteTaskChecklist {
  taskChecklistID: UUID!
}
type DeleteTaskChecklistPayload {
  ok: Boolean!
  taskChecklist: TaskChecklist!
}

extend type Mutation {
  createTaskComment(input: CreateTaskComment):
    CreateTaskCommentPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
  deleteTaskComment(input: DeleteTaskComment):
    DeleteTaskCommentPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
  updateTaskComment(input: UpdateTaskComment):
    UpdateTaskCommentPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
}

input CreateTaskComment {
  taskID: UUID!
  message: String!
}

type CreateTaskCommentPayload {
  taskID: UUID!
  comment: TaskComment!
}

input UpdateTaskComment {
  commentID: UUID!
  message: String!
}

type UpdateTaskCommentPayload {
  taskID: UUID!
  comment: TaskComment!
}

input DeleteTaskComment {
  commentID: UUID!
}

type DeleteTaskCommentPayload {
  taskID: UUID!
  commentID: UUID!
}

extend type Mutation {
  createTaskGroup(input: NewTaskGroup!):
    TaskGroup! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: PROJECT)
  updateTaskGroupLocation(input: NewTaskGroupLocation!):
    TaskGroup! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_GROUP)
  updateTaskGroupName(input: UpdateTaskGroupName!):
    TaskGroup! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_GROUP)
  deleteTaskGroup(input: DeleteTaskGroupInput!):
    DeleteTaskGroupPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_GROUP)
  duplicateTaskGroup(input: DuplicateTaskGroup!):
    DuplicateTaskGroupPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_GROUP)
  sortTaskGroup(input: SortTaskGroup!):
    SortTaskGroupPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_GROUP)
  deleteTaskGroupTasks(input: DeleteTaskGroupTasks!):
    DeleteTaskGroupTasksPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_GROUP)
}

input DeleteTaskGroupTasks {
  taskGroupID: UUID!
}

type DeleteTaskGroupTasksPayload {
  taskGroupID: UUID!
  tasks: [UUID!]!
}

input TaskPositionUpdate {
  taskID: UUID!
  position: Float!
}

type SortTaskGroupPayload {
  taskGroupID: UUID!
  tasks: [Task!]!
}

input SortTaskGroup {
  taskGroupID: UUID!
  tasks: [TaskPositionUpdate!]!
}

input DuplicateTaskGroup {
  projectID: UUID!
  taskGroupID: UUID!
  name: String!
  position: Float!
}

type DuplicateTaskGroupPayload {
  taskGroup: TaskGroup!
}

input NewTaskGroupLocation {
  taskGroupID: UUID!
  position: Float!
}

input UpdateTaskGroupName  {
  taskGroupID: UUID!
  name: String!
}

input DeleteTaskGroupInput {
  taskGroupID: UUID!
}

type DeleteTaskGroupPayload {
  ok: Boolean!
  affectedRows: Int!
  taskGroup: TaskGroup!
}

input NewTaskGroup {
  projectID: UUID!
  name: String!
  position: Float!
}

extend type Mutation {
  addTaskLabel(input: AddTaskLabelInput):
    Task! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
  removeTaskLabel(input: RemoveTaskLabelInput):
    Task! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
  toggleTaskLabel(input: ToggleTaskLabelInput!):
    ToggleTaskLabelPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)

}

input AddTaskLabelInput {
  taskID: UUID!
  projectLabelID: UUID!
}

input RemoveTaskLabelInput {
  taskID: UUID!
  taskLabelID: UUID!
}

input ToggleTaskLabelInput {
  taskID: UUID!
  projectLabelID: UUID!
}

type ToggleTaskLabelPayload {
  active: Boolean!
  task: Task!
}

extend type Mutation {
  createTask(input: NewTask!):
    Task! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK_GROUP)
  deleteTask(input: DeleteTaskInput!):
    DeleteTaskPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)

  updateTaskDescription(input: UpdateTaskDescriptionInput!):
    Task! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
  updateTaskLocation(input: NewTaskLocation!):
    UpdateTaskLocationPayload! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
  updateTaskName(input: UpdateTaskName!):
    Task! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
  setTaskComplete(input: SetTaskComplete!):
    Task! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
  updateTaskDueDate(input: UpdateTaskDueDate!):
    Task! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
  toggleTaskWatch(input: ToggleTaskWatch!):
    Task! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)

  assignTask(input: AssignTaskInput):
    Task! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
  unassignTask(input: UnassignTaskInput):
    Task! @hasRole(roles: [ADMIN, MEMBER], level: PROJECT, type: TASK)
}

input ToggleTaskWatch {
  taskID: UUID!
}

input NewTask {
  taskGroupID: UUID!
  name: String!
  position: Float!
  assigned: [UUID!]
}

input AssignTaskInput {
  taskID: UUID!
  userID: UUID!
}

input UnassignTaskInput {
  taskID: UUID!
  userID: UUID!
}

input UpdateTaskDescriptionInput {
  taskID: UUID!
  description: String!
}

type UpdateTaskLocationPayload {
  previousTaskGroupID: UUID!
  task: Task!
}

input UpdateTaskDueDate  {
  taskID: UUID!
  hasTime: Boolean!
  dueDate: Time
}

input SetTaskComplete {
  taskID: UUID!
  complete: Boolean!
}

input NewTaskLocation {
  taskID: UUID!
  taskGroupID: UUID!
  position: Float!
}

input DeleteTaskInput {
  taskID: UUID!
}

type DeleteTaskPayload {
  taskID: UUID!
}

input UpdateTaskName {
  taskID: UUID!
  name: String!
}

