/*
 * BEGIN FLOCK GPL
 * 
 * Copyright Flock Inc. 2005-2006
 * http://flock.com
 * 
 * This file may be used under the terms of of the
 * GNU General Public License Version 2 or later (the "GPL"),
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 * 
 * END FLOCK GPL
 */

#include "nsISupports.idl"
#include "nsIRDFDataSource.idl"
#include "nsIRDFRemoteDataSource.idl"
#include "nsISimpleEnumerator.idl"
#include "nsIDictionary.idl"
#include "nsIDOMDocument.idl"
#include "flockIError.idl"


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
interface flockIPhotoAPI; 
interface flockIPhoto; 

[scriptable, uuid(15706e56-37da-4ae2-98e5-915f5d9ad6b1)]
interface flockIPhotoPerson: nsISupports
{
    void init(in flockIPhotoAPI aService, in AString aID, in AString aUsername, in AString aFullName);
    attribute flockIPhotoAPI service;
    attribute AString username;
    attribute AString fullname;
    attribute AString id;
    attribute PRInt64 seq;
    attribute PRInt64 lastNewSeq;
    attribute boolean hasNew;
    attribute AString commentsFeedUrl;
};

[scriptable, uuid(cfcffc53-7c57-418c-ae84-f66ddd7b3f77)]
interface flockIPhotoAlbum: nsISupports
{
    attribute AString id;
    attribute AString title;
    attribute AString url;
};

[scriptable, uuid(9c86ff00-c9b4-11da-a94d-0800200c9a66)]
interface flockIPhotoAccount: nsISupports
{
    attribute AString username;
    attribute AString maxSpace;
    attribute AString usedSpace;
    attribute AString maxFileSize;
    attribute AString usageUnits;
    attribute boolean isPremium;
};

[scriptable, uuid(5b2aeb54-0955-46fc-b3d7-19b9593d099a)]
interface flockIPhotoUpload: nsISupports
{
    attribute string id;
    attribute string fileName;
    attribute string originalFileSpec;
    attribute string originalFilePath;
    attribute string workingFilePath;
    attribute string workingFileSpec;
    attribute string previewFileSpec;
    attribute string previewFilePath;
    attribute string thumbFileSpec;
    attribute string thumbFilePath;

    attribute AString title;
    attribute AString tags;
    attribute AString description;
    attribute string is_public;
    attribute string is_friend;
    attribute string is_family;

    attribute AString album;
    attribute string state;
    /*
     * states:
     *         (blank)
     *         uploading
     *         pending
     */
    attribute string rotation;
    attribute string crop;
};

[scriptable, uuid(03c80699-d437-466d-a9af-d28b4f3bc6e1)]
interface flockIPhotoUploadListener: nsISupports
{
    void onCreatePhotoUpload(in flockIPhotoUpload aUpload);
    void onUploadStart(in flockIPhotoUpload aUpload, in long aCount, in long aMax);
    void onUpload(in flockIPhotoUpload aUpload, in long aCount, in long aMax);
    void onUploadError(in flockIPhotoUpload aUpload, in long aCount, in long aMax, in flockIError aError);
    void onUploadComplete();
    void onUploadAdd(in flockIPhotoUpload aUpload);
    void onUploadRemove();
    void onUploadCreateError(in AString aFilename);
};

[scriptable, uuid(b5bcbdf9-2fb9-405d-9e5e-99004b8342a1)]
interface flockIPhotoAuthListener: nsISupports
{
    void onAuth();
    void onError(in flockIError aError);
};

[scriptable, uuid(2a470693-5a07-4a7a-bca9-3bf7b6841348)]
interface flockIPhotoUploadAPIListener: nsISupports
{
    void onUploadComplete(in flockIPhotoUpload aUpload);
    void onUploadFinalized(in flockIPhotoUpload aUpload, in flockIPhoto aPhoto);
    void onError(in flockIError aError);
};

[scriptable, uuid(79550209-2ab6-48f7-831d-20aa9bed2606)]
interface flockIPhoto: nsISupports
{
    attribute string id;
    attribute string webPageUrl;
    attribute string thumbnail;
    attribute string midSizePhoto;
    attribute string largeSizePhoto;// add
    attribute AUTF8String title;
    attribute AUTF8String username;
    attribute AUTF8String userid;
    attribute string is_public;
    // extend this to allow for friend/family/privacy
};

[scriptable, uuid(8dd40991-9a61-4d61-bfd5-219d8939f6ef)]
interface flockIPhotoAPIListener: nsISupports
{
    void onResult(in nsIDOMDocument aXML);
    void onSearchResult(in nsISimpleEnumerator aEnumerator);
    void onGetContactsResult(in nsISimpleEnumerator aEnumerator);
    void onFindByUsernameResult(in flockIPhotoPerson aPerson);
    void onGetValidPerson(in flockIPhotoPerson aPerson);
    void onGetAlbumsResult(in nsISimpleEnumerator aEnumerator);
    void onGetPhoto(in flockIPhoto aPhoto);
    void onCreateAlbum(in flockIPhotoAlbum aAlbum);
    void onGetAccountStatus(in flockIPhotoAccount aAccount);
    void onGetMostRecentPhotoForList(in long aChange);
    void onError(in flockIError aError);

    const long LIST_NO_CHANGE  = 0;
    const long LIST_NEED_SAVE  = 1;
    const long LIST_HAS_NEW = 2;
};

[scriptable, uuid(cae54dc1-5a17-4e18-a84d-b52c93a8319a)]
interface flockIPhotoAPI: nsISupports 
{
    void login(in flockIPhotoAuthListener aListener);
    void logout();
    flockIPhotoPerson getAuthPerson();
    void upload(in flockIPhotoUploadAPIListener aListener, in AString aFile, in nsIDictionary aParams, in flockIPhotoUpload aUpload);
    void cancelUpload();
    void call(in flockIPhotoAPIListener aListener, in AString aMethod, in nsIDictionary aParams);
    void authenticatedCall(in flockIPhotoAPIListener aListener, in AString aMethod, in nsIDictionary aParams);

    boolean supportsFeature(in AString aFeature);

    void getAlbums(in flockIPhotoAPIListener aListener);
    void createAlbum(in flockIPhotoAPIListener aListener, in AString aAlbumName);
    void getPhoto(in flockIPhotoAPIListener aListener, in AString aPhotoID);
    void getContacts(in flockIPhotoAPIListener aListener);
    void findByUsername(in flockIPhotoAPIListener aListener, in AString aUsername);
    void getValidPerson(in flockIPhotoAPIListener aListener, in AString aURL);
    void getMostRecentPhotoForList(in flockIPhotoAPIListener aListener, in nsISimpleEnumerator aEnumerator);
    void search(in flockIPhotoAPIListener aListener, in AString aUserid, in AString aTags, 
                in AString aFreeText, in long aCount, in long aPage);
    void getAccountStatus(in flockIPhotoAPIListener aListener);

    // all uploading code needs refactoring - rotation and cropping must be
    // moved to service layer to clean this up
    void upload2(in flockIPhotoUploadAPIListener aListener, in flockIPhotoUpload aUpload,  in AString aFilename);//yes, that's right - cstring

    
    readonly attribute flockIPhotoPerson firstRunPerson;
    readonly attribute AString serviceName; //localized
    readonly attribute ACString shortName; //localized
    readonly attribute boolean isLoggedIn;
    readonly attribute boolean isUploading;
    readonly attribute AString iconUrl;

    const long LOGGED_OUT  = 0;
    const long LOGGING_IN  = 1;
    const long LOGGED_IN   = 2;
    const long LOGIN_ERROR = 3;
    readonly attribute long authState;
};

[scriptable, uuid(74a7c5a0-97d7-4ac0-8728-305e74849453)]
interface flockIPhotoUploadService: nsIRDFDataSource
{
    void createPhotoUpload(in flockIPhotoUploadListener aListener, in AString aFileName);

    void upload(in flockIPhotoAPI aAPI);
    void singleUpload(in flockIPhotoUploadAPIListener aListener, in flockIPhotoAPI aAPI, in flockIPhotoUpload aUpload);
    
    void cancelUpload();

    void addPhotoUpload(in flockIPhotoUpload aReference, in flockIPhotoUpload aUpload);
    void savePhotoUpload(in flockIPhotoUpload aUpload);
    void removePhotoUpload(in flockIPhotoUpload aUpload);
    void reorderPhotoUpload(in flockIPhotoUpload aReference, in flockIPhotoUpload aUpload);
    flockIPhotoUpload getPhotoUpload(in AString aURI);
    void addListener(in flockIPhotoUploadListener aListener);
    void removeListener(in flockIPhotoUploadListener aListener);
    void cropPhotoUpload(in flockIPhotoUpload aUpload, in double aX1, in double aY1, in double aX2, in double aY2);
    void revertPhotoUpload(in flockIPhotoUpload aUpload);
    void rotatePhotoUpload(in flockIPhotoUpload aUpload, in PRInt32 aDegrees);
    void save();// should go away
    void cleanPhotoUploadCache();

    readonly attribute boolean isUploading;
};

[scriptable, uuid(90ebb22d-c468-4db2-979d-9c32f5d65d78)]
interface flockIPhotoAPIManagerListener: nsISupports
{
    void onAPIStateChange(in flockIPhotoAPI aAPI);
    void onError(in flockIError aError);
};

[scriptable, uuid(932bfd1b-be5c-408b-94df-984ff37ce0da)]
interface flockIPhotoAPIManager: nsISupports
{
    //void registerAPI(in flockIPhotoAPI aService, in ACString aShortname);//private
    void addListener(in flockIPhotoAPIManagerListener aListener);
    void removeListener(in flockIPhotoAPIManagerListener aListener);
    void doLogin(in ACString aShortname);
    void doLogout(in ACString aShortname);
    flockIPhotoAPI getAPIFromShortname(in ACString aShortname);
    AString getShortnameFromAPI(in flockIPhotoAPI aAPI);
    readonly attribute nsISimpleEnumerator services;

    void addPreferredService(in ACString aShortname);
    void removePreferredService(in ACString aShortname);
    readonly attribute nsISimpleEnumerator preferredServices;
    flockIPhotoAPI getDefaultService();
    void setDefaultService(in ACString aShortname);
};

[scriptable, uuid(6a565280-3790-4889-b491-5e24c84a6d3a)]
interface flockIPhotoPeopleServiceListener: nsISupports
{
    void onUpdate();
    void onNewPhotos();
    void onNewPhotosTouched();
};

[scriptable, uuid(6a4c4878-fd98-4e4e-97b8-06559ba934b3)]
interface flockIPhotoPeopleService: nsIRDFDataSource
{
    void addListener(in flockIPhotoPeopleServiceListener aListener);
    void removeListener(in flockIPhotoPeopleServiceListener aListener);
    flockIPhotoPerson getPhotoPersonByURI(in AString aURI);
    flockIPhotoPerson getPhotoPersonByID(in flockIPhotoAPI aService, in AString aID);
    flockIPhotoPerson getPhotoPerson(in flockIPhotoPerson aPerson);

    void addToRecent(in flockIPhotoPerson aPerson);
    void clearRecent();
    flockIPhotoPerson getMostRecentPhotoPerson();

    void addToList(in long aListID, in flockIPhotoPerson aPerson);
    void removeFromList(in long aListID, in flockIPhotoPerson aPerson);
    void clearList(in long aListID);
    boolean isInList(in long aListID, in flockIPhotoPerson aPerson);

    void registerList(in long aListID, in ACString aShortName, in AString aName);

    void removePerson(in flockIPhotoPerson aPerson);

    boolean hasNewPhotos(in flockIPhotoPerson aPerson); //#hasNew
    PRTime getLastUpdated(in flockIPhotoPerson aPerson); //#hasNew 
    void clearHasNewPhotos(in flockIPhotoPerson aPerson);
    void clearAllHasNewPhotos();

    void findNewPhotosForList(in long aListID);
    readonly attribute boolean isFindingNewPhotosForList;
    void syncContacts();

    nsISimpleEnumerator getListEnumerator(in long aListID);

    void update();
    attribute long updateInterval;
    readonly attribute PRTime lastUpdate;
    readonly attribute boolean hasNew;

    readonly attribute nsISimpleEnumerator people;
    const long LIST_WATCHED = 1;
    const long LIST_RECENT = 2;
    const long LIST_CONTACTS = 3;
    const long LIST_ACCOUNTS = 4;
};

/*
[scriptable, uuid(c0ac26be-e069-454c-a334-cb7d5b2e5800)]
interface flockIPhotoWatchService: nsISupports
{
    void update();
    attribute long updateInterval;
    attribute PRTime lastUpdate;
};
*/
