   * The default TCP port used by the client if no `port` variable is specified during UoACalendarClient instantiation.
   *
   * @name UoACalendarClient#DEFAULT_PORT
-  * @type Number
+  * @type number
   * @default 345
   ###
 

  ###*
  * Retrieve full list of calendars
  *
  * @param {UoACalendarClient~listCalendarsSuccess} onSuccess - Success callback function
  * @param {UoACalendarClient~listCalendarsError} onError - Error callback function
  ###

  listCalendars: (onSuccess, onError) ->
    @sendRequest('/calendars/', 'GET', 0, onSuccess, onError)

  ###*
  * @callback UoACalendarClient~listCalendarsSuccess
  * @param {res} Response
  * @param {data} Deserialized data
  ###

  ###*
  * @callback UoACalendarClient~listCalendarsError
  * @param {res} Response
  * @param {data} ?
  ###

  ###*
  * Retrieve a particular calendar
  * @param {Number} id - id of the calendar
  * @param {UoACalendarClient~getCalendarSuccess} onSuccess - Success callback function
  * @param {UoACalendarClient~getCalendarError} onError - Error callback function
  ###

  getCalendar: (id, onSuccess, onError) ->
    @sendRequest('/calendars/' + id + '/', 'GET', 0, onSuccess, onError)

  ###*
  * @callback UoACalendarClient~getCalendarSuccess
  * @param {res} Response
  * @param {data} Deserialized data
  ###

  ###*
  * @callback UoACalendarClient~getCalendarError
  * @param {res} Response
  * @param {data} ?
  ###

  ###*
  * Add a new calendar providing the new calendar's name
  * @param {String} name - Name of calendar
  * @param {UoACalendarClient~addCalendarSuccess} onSuccess - Success callback function
  * @param {UoACalendarClient~addCalendarError} onError - Error callback function
  ###

  addCalendar: (name, onSuccess, onError) ->
    @sendRequest('/calendars/', 'POST', {name: name}, onSuccess, onError)

  ###*
  * @callback UoACalendarClient~addCalendarSuccess
  * @param {res} Response
  * @param {data} Deserialized data
  ###

  ###*
  * @callback UoACalendarClient~addCalendarError
  * @param {res} Response
  * @param {data} ?
  ###

  ###*
  * Delete an existing calendar given its id
  * @param {Number} id - id of calendar
  * @param {UoACalendarClient~deleteCalendarSuccess} onSuccess - Success callback function
  * @param {UoACalendarClient~deleteCalendarError} onError - Error callback function
  ###

  deleteCalendar: (id, onSuccess, onError) ->
    @sendRequest('/calendars/' + id + '/', 'DELETE', {}, onSuccess, onError)

  ###*
  * @callback UoACalendarClient~deleteCalendarSuccess
  * @param {res} Response
  * @param {data} Deserialized data
  ###

  ###*
  * @callback UoACalendarClient~deleteCalendarError
  * @param {res} Response
  * @param {data} ?
  ###

  ###*
  * Retrieve the full list of events of an existing calendar given its id
  * @param {Number} calendarId - Id of calendar
  * @param {UoACalendarClient~listEventsSuccess} onSuccess - Success callback function
  * @param {UoACalendarClient~listEventsError} onError - Error callback function
  ###

  listEvents: (calendarId, onSuccess, onError) ->
    @sendRequest('/calendars/' + calendarId + '/events/', 'GET', 0, onSuccess, onError)

  ###*
  * @callback UoACalendarClient~listEventsSuccess
  * @param {res} Response
  * @param {data} Deserialized events dictionary
  ###

  ###*
  * @callback UoACalendarClient~listEventsError
  * @param {res} Response
  * @param {data} ?
  ###

  ###*
  * Add an event to a particular calendar. Your own data fields can be added to the JSON event object, for
  * example, if you wanted to add an 'exercise' type to an event do the following: {"title": "My calendar", "exercise": "Run"}
  *
  * @param {Number} calendarId - Id of calendar
  * @param {Object} event - Event JSON object
  * @param {String} event.title - Event title
  * @param {String=} event.description - Event description
  * @param {String=} event.location - Event location
  * @param {String=} event.summary - Event summary
  * @param {Date=} event.start - Event start date & time
  * @param {Date=} event.end - Event end date & time
  * @param {String=} event.status - Event status
  * @param {String=} event.reminder - Event reminder
  * @param {Boolean=} event.todo - Whether event still to be done
  * @param {Boolean=} event.allDay - Whether event occurs all day
  * @param {String=} event.url - Event url
  * @param {UoACalendarClient~addEventSuccess} onSuccess - Success callback function
  * @param {UoACalendarClient~addEventError} onError - Error callback function
  ###

  addEvent: (calendarId, event, onSuccess, onError) ->
    @sendRequest('/calendars/' + calendarId + '/events/', 'POST', event, onSuccess, onError)

  ###*
  * Event object
  *
  * @class Event
  ###

  ###*
  * @callback UoACalendarClient~addEventSuccess
  * @param {res} Response
  * @param {data} Deserialized events dictionary
  ###

  ###*
  * @callback UoACalendarClient~addEventError
  * @param {res} Response
  * @param {data} ?
  ###

  ###*
  * Delete an existing event from a calendar giving their ids
  *
  * @param {Number} calendarId - id of calendar
  * @param {Number} eventId - id of event
  * @param {UoACalendarClient~deleteEventSuccess} onSuccess - Success callback function
  * @param {UoACalendarClient~deleteEventError} onError - Error callback function
  ###

  deleteEvent: (calendarId, eventId, onSuccess, onError) ->
    @sendRequest('/calendars/' + calendarId + '/events/' + eventId + '/', 'DELETE', 0, onSuccess, onError)

# Update an existing event from a calendar giving their IDs
#
# ```javascript
# client.updateEvent(calendarId, eventId, { title: "Event Title", ... }
#   // onSuccess callback
#   function(res, data) {
#       // response
#       console.log(res);
#       // deserialized updated event object data
#       console.log(data);
#   },
#   // onError callback
#   function(res, data) {
#       ...
#   }
# );
# ```
#
  updateEvent: (calendarId, eventId, event, onSuccess, onError) ->
    @sendRequest('/calendars/' + calendarId + '/events/' + eventId + '/', 'PATCH', event, onSuccess, onError)

# Find events from an existing calendar within a given time range
#
# ```javascript
# client.updateEvent(calendarId, new Date(1977, 5, 25), Date.now(),
#   // onSuccess callback
#   function(res, data) {
#       // response
#       console.log(res);
#       // deserialized events dictionary
#       console.log(data);
#   },
#   // onError callback
#   function(res, data) {
#       ...
#   }
# );
# ```
#
  findEvents: (calendarId, startDate, endDate, onSuccess, onError) ->
    toUTCString = (date) ->
      return (new Date(date.getTime() + date.getTimezoneOffset() * 60000)).toISOString()

      onSuccess, onError
    )

  ###*
  * Callback, returns events from a particular calendar within a date range.
  *
  * @callback onFindEventsSuccess
  * @param {HttpResponse} res - HTTP response
  * @param {Array.<{}>} data - Array of events
  *
  * @example <caption>Example output</caption>
  * res: {"offset":0,"readable":true,"_events":{},"statusCode":204,"headers":{"content-type":"text/plain; charset=UTF-8"}}
  * data: [{},
  *        {}]
  ###

  ###*
  * Callback function, executed when finding events failed.
  *
  * @callback onFindEventsError
  * @param {HttpResponse} res - HTTP response
  * @param {ErrorMessage} data - Error message.
  *
  * @example <caption>Example output</caption>
  * todo: insert example
  ###

  ###*
  * @typedef {Object} HttpResponse
  * @property {number} offset -
  * @property {boolean} readable -
  * @property {number} statusCode - See [HTTP status codes]{@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
  * @property {Object} headers -
  * @property {string} headers.content-type -
  *
  * @example
  * {"offset":30,"readable":true,"_events":{},"statusCode":200,"headers":{"content-type":"application/json"}}
  ###

  ###*
  *
  * @typedef {Object} ErrorMessage
  * @property {string} detail - Reason for error.
  *
  * @example
  * {detail: "You do not have permission to perform this action."}
  ###

exports.UoACalendarClient = UoACalendarClient

module.exports = (config) ->
