define(
    ['Global', 'User', 'Resources'],
    function (Global, user, resources) {
        'use strict';
        var WaitListEntryRecall = Backbone.Model.extend({
            defaults: {
                "accessionno": "",
                "appointmentLength": "",
                "clinicId": "",
                "clinicName": "",
                "comment": "",
                "dfn": "",
                "fastNonFasting": "",
                "object-type": "WaitListEntry",
                "patientName": "",
                "provider": "",
                "recallDate": "",
                "ssn": "",
                "user": "",
                "waitListType": "RECALL"
            },

            initialize: function () {
            },

            convertPercentage: function (pct) {
                return pct >= 50 ? "50 +" : pct < 50 && pct > 0 ? "50 -" : pct !== "" ? "NO" : "";
            },

            parse: function (response) {
                var facilityCode = user.toJSON()['vistaLocation'],
                    patientLink = resources.get('system-root').get('href') + "patient/dfn-" + facilityCode + "/" + response.dfn;

                response.patientLink = patientLink;
                response.type = response.waitListType;
                response.fastNonFasting = response.fastNonFasting === "f" ? "Yes" : "No";
                response.recallDate = formatDate(new Date(response.recallDate));
                response.recallDate1 = formatDate(new Date(response.recallDate1));
                response.waitListId = this.getWaitlistId(response);
                response.detailsLink = response.waitListId;

                return response;
            },

            getWaitlistId: function(response){
                return response.dfn + ";" + response.clinicId + ";" + response.recallDate;
            }
        });

        WaitListEntryRecall.singleInstance = null;

        WaitListEntryRecall.instance = function (attributes) {
            if (attributes) {
                WaitListEntryRecall.singleInstance = new WaitListEntryRecall(attributes);
            } else {
                WaitListEntryRecall.singleInstance = WaitListEntryRecall.singleInstance || new WaitListEntryRecall();
            }
            return WaitListEntryRecall.singleInstance;
        };

        WaitListEntryRecall.clearInstance = function () {
            WaitListEntryRecall.singleInstance = null;
        };

        return WaitListEntryRecall;
    }
);
