/* Copyright 2009 Palm, Inc.  All rights reserved. */

Photos.Model.FacebookFriends = Class.create(Photos.Model.Friends, {
	initialize: function($super, accountID, contactName) {
		if (contactName === undefined) {
			throw "Invalid params to new FacebookFriends()!";
		}
		$super(accountID);
		this.contactName = contactName;
	},

	getTitle: function() {
		return $L("#{name}'s friends").interpolate({
			name: this.contactName
		});
	},

	request: function(filter, offset, limit, done) {
		this.controller.serviceRequest(
			'palm://com.palm.photo.facebook', {
				method: "getContactList",
				onSuccess: this.translate.bind(this, done),
				parameters: {
					offset: offset,
					limit: limit,
					filter: filter
				}
		});
	},

	translate: function(done, response) {
		if (!response || !response.returnValue) {
			Mojo.Log.error("Error: " + Object.toJSON(response));
			done([], 0);
			return;
		}

		for (var i = 0, len = response.contacts.length; i < len; i++) {
			var contact = response.contacts[i];
			contact.contactID = contact.cid;
			contact.contactName = contact.name;
			contact.contactIcon = contact.icon;
		}
		done(response.contacts, parseInt(response.contacts.length, 10));
	}
});

