define([
    'Global'
],
    function(Global) {
        var BookedAppointment = Backbone.Model.extend({
            defaults: {
                "object-type": "",
                "appointmentTime": "",
				"appointmentId": "",
				"apptLength": 30,
				"bookingNote": "",
				"clinic": {
					"askForCheckIn": "",
					"name": ""
				},
				"currentStatus": "",
				"providerName": "",
				"purpose": "",
                "type": ""
            },
			initialize: function () {
				Global.getUtilities().flattenLinks(this);
			},
            parse: function(response) {
				var appointmentDate = new Date(response.appointmentTime || response.appointmentStartDate);

				response.appointmentId = appointmentDate + ";" + response.clinicName;
				response.start = appointmentDate;
				response.appointmentDate = formatDate(appointmentDate);
				response.appointmentTime = formatTime(appointmentDate);
				response.apptLength = response.appointmentLength || 30;
				response.end = addToDate(0, 0, 0, 0, response.apptLength, 0, 0, appointmentDate);
				response.endTime = formatDate(response.end);
				response.detailsLink = response.appointmentId;
				response.clinicName = response.clinic.name;
				response.clinicId = response.clinic.id;
				response.askForCheckIn = response.clinic.askForCheckIn ? "Yes" : "No";

                return response;
            }
        });

        BookedAppointment.singleInstance = null;

        BookedAppointment.instance = function () {
            BookedAppointment.singleInstance = BookedAppointment.singleInstance || new BookedAppointment();
            return BookedAppointment.singleInstance;
        };

        return BookedAppointment;
    }
);

