import { Socket } from "socket.io";
import { on_login } from "./commands/on-connect";
import { on_create_label } from "./commands/on-create-label";

import { on_disconnect } from "./commands/on-disconnect";
import { on_quick_assign_or_remove } from "./commands/on-quick-assign-or-remove";
import { on_quick_task } from "./commands/on-quick-task";
import { on_task_end_date_change } from "./commands/on-task-end-date-change";
import { on_task_label_change } from "./commands/on-task-labels-change";
import { on_task_name_change } from "./commands/on-task-name-change";
import { on_task_priority_change } from "./commands/on-task-priority-change";
import { on_task_status_change } from "./commands/on-task-status-change";
import { on_task_start_date_change } from "./commands/on-task-start-date-change";
import { SocketEvents } from "./events";
import { log } from "./util";
import { on_time_estimation_change } from "./commands/on-time-estimation-change";
import { on_task_description_change } from "./commands/on-task-description-change";
import { on_get_task_progress } from "./commands/on-get-task-progress";
import { on_task_timer_start } from "./commands/on-task-timer-start";
import { on_task_timer_stop } from "./commands/on-task-timer-stop";
import { on_task_sort_order_change } from "./commands/on-task-sort-order-change";
import { on_join_project_room as on_join_or_leave_project_room } from "./commands/on-join-or-leave-project-room";
import { on_task_subscriber_change } from "./commands/on-task-subscriber-change";
import { on_project_subscriber_change } from "./commands/on-project-subscriber-change";
import { on_task_phase_change } from "./commands/on-task-phase-change";
import { on_roadmap_sort_order_change } from "./commands/on-roadmap-sort-order-change";
import { on_phase_start_date_change } from "./commands/on-phase-start-date-change";
import { on_phase_end_date_change } from "./commands/on-phase-end-date-change";
import { on_project_health_change } from "./commands/on-project-health-change";
import { on_project_start_date_change } from "./commands/on-project-start-date-change";
import { on_project_end_date_change } from "./commands/on-project-end-date-change";
import { on_project_status_change } from "./commands/on-project-status-change";
import { on_project_category_change } from "./commands/on-project-category-change";
import { on_create_project_category } from "./commands/on-create-project-category";
import { on_pt_create_label } from "./commands/on_pt_create_label";
import { on_pt_name_change } from "./commands/on_pt_name_change";
import { on_pt_quick_task } from "./commands/on_pt_quick_task";
import { on_pt_task_description_change } from "./commands/on_pt_task_description_change";
import { on_pt_task_labels_change } from "./commands/on_pt_task_labels_change";
import { on_pt_task_name_change } from "./commands/on_pt_task_name_change";
import { on_pt_task_phase_change } from "./commands/on_pt_task_phase_change";
import { on_pt_task_priority_change } from "./commands/on_pt_task_priority_change";
import { on_pt_task_sort_order_change } from "./commands/on_pt_task_sort_order_change";
import { on_pt_task_status_change } from "./commands/on_pt_task_status_change";
import { on_pt_task_time_estimation_change } from "./commands/on_pt_task_time_estimation_change";
import { on_gannt_drag_change } from "./commands/on_gannt_drag_change";
import { on_schedule_member_start_date_change } from "./commands/on_schedule_member_start_date_change";
import { on_schedule_member_end_date_change } from "./commands/on_schedule_member_end_date_change";
import { on_schedule_member_allocation_create } from "./commands/on_schedule_member_allocation_create";
import { on_task_billable_change } from "./commands/on-task-billable-change";
import { on_task_recurring_change } from "./commands/on-task-recurring-change";
import { on_task_assignees_change } from "./commands/on-task-assignees-change";
import { on_task_custom_column_update } from "./commands/on_custom_column_update";
import { on_custom_column_pinned_change } from "./commands/on_custom_column_pinned_change";
import { on_update_task_progress } from "./commands/on-update-task-progress";
import { on_update_task_weight } from "./commands/on-update-task-weight";
import { on_get_task_subtasks_count } from "./commands/on-get-task-subtasks-count";
import { on_get_done_statuses } from "./commands/on-get-done-statuses";

export function register(io: any, socket: Socket) {
  log(socket.id, "client registered");

  socket.on(SocketEvents.LOGIN.toString(), id => on_login(io, socket, id));
  socket.on(SocketEvents.QUICK_TASK.toString(), data => on_quick_task(io, socket, data));
  socket.on(SocketEvents.QUICK_ASSIGNEES_UPDATE.toString(), data => on_quick_assign_or_remove(io, socket, data));
  socket.on(SocketEvents.TASK_STATUS_CHANGE.toString(), data => on_task_status_change(io, socket, data));
  socket.on(SocketEvents.TASK_PRIORITY_CHANGE.toString(), data => on_task_priority_change(io, socket, data));
  socket.on(SocketEvents.TASK_NAME_CHANGE.toString(), data => on_task_name_change(io, socket, data));
  socket.on(SocketEvents.TASK_LABELS_CHANGE.toString(), data => on_task_label_change(io, socket, data));
  socket.on(SocketEvents.CREATE_LABEL.toString(), data => on_create_label(io, socket, data));
  socket.on(SocketEvents.TASK_START_DATE_CHANGE.toString(), data => on_task_start_date_change(io, socket, data));
  socket.on(SocketEvents.TASK_END_DATE_CHANGE.toString(), data => on_task_end_date_change(io, socket, data));
  socket.on(SocketEvents.TASK_TIME_ESTIMATION_CHANGE.toString(), data => on_time_estimation_change(io, socket, data));
  socket.on(SocketEvents.TASK_DESCRIPTION_CHANGE.toString(), data => on_task_description_change(io, socket, data));
  socket.on(SocketEvents.GET_TASK_PROGRESS.toString(), data => on_get_task_progress(io, socket, data));
  socket.on(SocketEvents.TASK_TIMER_START.toString(), data => on_task_timer_start(io, socket, data));
  socket.on(SocketEvents.TASK_TIMER_STOP.toString(), data => on_task_timer_stop(io, socket, data));
  socket.on(SocketEvents.TASK_SORT_ORDER_CHANGE.toString(), data => on_task_sort_order_change(io, socket, data));
  socket.on(SocketEvents.JOIN_OR_LEAVE_PROJECT_ROOM.toString(), data => on_join_or_leave_project_room(io, socket, data));
  socket.on(SocketEvents.TASK_SUBSCRIBERS_CHANGE.toString(), data => on_task_subscriber_change(io, socket, data));
  socket.on(SocketEvents.PROJECT_SUBSCRIBERS_CHANGE.toString(), data => on_project_subscriber_change(io, socket, data));
  socket.on(SocketEvents.TASK_PHASE_CHANGE.toString(), data => on_task_phase_change(io, socket, data));
  socket.on(SocketEvents.ROADMAP_SORT_ORDER_CHANGE.toString(), data => on_roadmap_sort_order_change(io, socket, data));
  socket.on(SocketEvents.PHASE_START_DATE_CHANGE.toString(), data => on_phase_start_date_change(io, socket, data));
  socket.on(SocketEvents.PHASE_END_DATE_CHANGE.toString(), data => on_phase_end_date_change(io, socket, data));
  socket.on(SocketEvents.PROJECT_HEALTH_CHANGE.toString(), data => on_project_health_change(io, socket, data));
  socket.on(SocketEvents.PROJECT_START_DATE_CHANGE.toString(), data => on_project_start_date_change(io, socket, data));
  socket.on(SocketEvents.PROJECT_END_DATE_CHANGE.toString(), data => on_project_end_date_change(io, socket, data));
  socket.on(SocketEvents.PROJECT_STATUS_CHANGE.toString(), data => on_project_status_change(io, socket, data));
  socket.on(SocketEvents.PROJECT_CATEGORY_CHANGE.toString(), data => on_project_category_change(io, socket, data));
  socket.on(SocketEvents.CREATE_PROJECT_CATEGORY.toString(), data => on_create_project_category(io, socket, data));
  socket.on(SocketEvents.PT_QUICK_TASK.toString(), data => on_pt_quick_task(io, socket, data));
  socket.on(SocketEvents.PT_NAME_CHANGE.toString(), data => on_pt_name_change(io, socket, data));
  socket.on(SocketEvents.PT_TASK_SORT_ORDER_CHANGE.toString(), data => on_pt_task_sort_order_change(io, socket, data));
  socket.on(SocketEvents.PT_TASK_NAME_CHANGE.toString(), data => on_pt_task_name_change(io, socket, data));
  socket.on(SocketEvents.PT_TASK_TIME_ESTIMATION_CHANGE.toString(), data => on_pt_task_time_estimation_change(io, socket, data));
  socket.on(SocketEvents.PT_TASK_DESCRIPTION_CHANGE.toString(), data => on_pt_task_description_change(io, socket, data));
  socket.on(SocketEvents.PT_TASK_LABELS_CHANGE.toString(), data => on_pt_task_labels_change(io, socket, data));
  socket.on(SocketEvents.PT_CREATE_LABEL.toString(), data => on_pt_create_label(io, socket, data));
  socket.on(SocketEvents.PT_TASK_PHASE_CHANGE.toString(), data => on_pt_task_phase_change(io, socket, data));
  socket.on(SocketEvents.PT_TASK_STATUS_CHANGE.toString(), data => on_pt_task_status_change(io, socket, data));
  socket.on(SocketEvents.PT_TASK_PRIORITY_CHANGE.toString(), data => on_pt_task_priority_change(io, socket, data));
  socket.on(SocketEvents.GANNT_DRAG_CHANGE.toString(), data => on_gannt_drag_change(io, socket, data));
  socket.on(SocketEvents.SCHEDULE_MEMBER_ALLOCATION_CREATE.toString(), data => on_schedule_member_allocation_create(io, socket, data));
  socket.on(SocketEvents.SCHEDULE_MEMBER_START_DATE_CHANGE.toString(), data => on_schedule_member_start_date_change(io, socket, data));
  socket.on(SocketEvents.SCHEDULE_MEMBER_END_DATE_CHANGE.toString(), data => on_schedule_member_end_date_change(io, socket, data));
  socket.on(SocketEvents.TASK_BILLABLE_CHANGE.toString(), data => on_task_billable_change(io, socket, data));
  socket.on(SocketEvents.TASK_RECURRING_CHANGE.toString(), data => on_task_recurring_change(io, socket, data));
  socket.on(SocketEvents.TASK_ASSIGNEES_CHANGE.toString(), data => on_task_assignees_change(io, socket, data));
  socket.on(SocketEvents.TASK_CUSTOM_COLUMN_UPDATE.toString(), data => on_task_custom_column_update(io, socket, data));
  socket.on(SocketEvents.CUSTOM_COLUMN_PINNED_CHANGE.toString(), data => on_custom_column_pinned_change(io, socket, data));
  socket.on(SocketEvents.UPDATE_TASK_PROGRESS.toString(), data => on_update_task_progress(io, socket, data));
  socket.on(SocketEvents.UPDATE_TASK_WEIGHT.toString(), data => on_update_task_weight(io, socket, data));
  socket.on(SocketEvents.GET_TASK_SUBTASKS_COUNT.toString(), (taskId) => on_get_task_subtasks_count(io, socket, taskId));
  socket.on(SocketEvents.GET_DONE_STATUSES.toString(), (projectId, callback) => on_get_done_statuses(io, socket, projectId, callback));
  
  // socket.io built-in event
  socket.on("disconnect", (reason) => on_disconnect(io, socket, reason));
}
