using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using EQNetwork.Objects;
using EQNetwork.Interfaces;
using EQNetwork.Utility;

namespace EQNetwork.Services
{
    public partial class UserService : IUserService
    {
        public EQTask Get(int userId, Action<User, EQException> onComplete) { return _api.User_Get(userId, onComplete); }
        public EQTask Get(string username, Action<User, EQException> onComplete) { return _api.User_Get(username, onComplete); }
        public EQTask Get(Action<User, EQException> onComplete) { return _api.User_Get(onComplete); }

        public EQTask Create(User user, Action<Session, EQException> onComplete)
        {
            return _api.User_Create(user,
                (User user2, EQException ex) => // onComplete
                {
                    if (ex == null)
                    {
                        _api.Session_Create(user2.Username, user2.Password,
                            (Session session, EQException ex2) => // onComplete
                            {
                                _eq.Session = session;
                                onComplete(session, ex2);
                            }
                        );
                    }
                    else onComplete(null, ex);
                }
            );
        }

        public EQTask Update(User user, Action<User, EQException> onComplete) { return _api.User_Update(user, onComplete); }
        public EQTask UploadIcon(string path, Action<User, EQException> onComplete) { return UploadIcon(new FileUploadSpec(path), onComplete); }
        public EQTask UploadIcon(FileUploadSpec fileUploadSpec, Action<User, EQException> onComplete)
        {
            User user = new User();
            user.Icon = fileUploadSpec;
            return Update(user, onComplete);
        }
        public EQTask DeleteIcon(Action<User, EQException> onComplete)
        {
            User user = new User();
            user.Icon = null;
            return Update(user, onComplete);
        }
        public EQTask LinkFacebook(string accessToken, DateTime expirationDate, Action<User, EQException> onComplete) { return _api.User_UpdateFacebook(null, accessToken, expirationDate, onComplete); }
        public EQTask UnlinkFacebook(Action<User, EQException> onComplete) { return _api.User_UpdateFacebook(null, null, null, onComplete); }
        public EQTask LinkTwitter(string twitterUserId, string screenName, string oAuthToken, string oAuthTokenSecret, Action<User, EQException> onComplete) { return _api.User_UpdateTwitter(null, twitterUserId, screenName, oAuthToken, oAuthTokenSecret, onComplete); }
        public EQTask UnlinkTwitter(Action<User, EQException> onComplete) { return _api.User_UpdateTwitter(null, null, null, null, null, onComplete); }

        public EQTask Delete(Action<EQException> onComplete) { return _api.User_Delete(onComplete); }
        public EQTask Delete(User user, Action<EQException> onComplete) { return _api.User_Delete(user, onComplete); }
        public EQTask Delete(int userId, Action<EQException> onComplete) { return _api.User_Delete(userId, onComplete); }

        public EQTask EmailAccounts(string email, Action<string, EQException> onComplete) { return _api.User_EmailAccounts(email, onComplete); }

        public EQTask ListCollections(ListCollectionsContext listCollectionsContext, PagingParameters pagingParameters, Action<List<Collection>, bool, EQException> onComplete) { return _api.User_ListCollections(listCollectionsContext, pagingParameters, onComplete); }
        public EQTask ListCollections(int userId, ListCollectionsContext listCollectionsContext, PagingParameters pagingParameters, Action<List<Collection>, bool, EQException> onComplete) { return _api.User_ListCollections(userId, listCollectionsContext, pagingParameters, onComplete); }

        public EQTask Search(string search, PagingParameters pagingParameters, Action<List<User>, bool, EQException> onComplete) { return _api.User_Search(search, pagingParameters, onComplete); }
        public EQTask ListUsers(ListUsersContext listUsersContext, PagingParameters pagingParameters, Action<List<User>, bool, EQException> onComplete) { return _api.User_ListUser(listUsersContext, pagingParameters, onComplete); }
        public EQTask ListFavoritedContentFiles(ListContentFilesContext listContentFilesContext, PagingParameters pagingParameters, Action<List<ContentFile>, bool, EQException> onComplete) { return _api.User_ListFavoritedContentFiles(listContentFilesContext, pagingParameters, onComplete); }

        public EQTask RequestPasswordReset(string username, Action<EQException> onComplete) { return _api.User_RequestPasswordReset(username, onComplete); }
        public EQTask ResendConfirmationEmail(Action<EQException> onComplete) { return _api.User_ResendConfirmationEmail(onComplete); }
        public EQTask ResetPassword(Guid passwordResetGuid, string password, Action<EQException> onComplete) { return _api.User_ResetPassword(passwordResetGuid, password, onComplete); }

        public EQTask Purchase(PurchaseContext purchaseContext, Action<PurchaseTransaction, EQException> onComplete) { return _api.User_Purchase(purchaseContext, onComplete); }

        public EQTask FacebookFindFriends(string search, Db.SocialSearchType socialSearchType, PagingParameters pagingParameters, Action<List<Friend>, bool, EQException> onComplete) { return _api.User_FacebookFindFriends(search, socialSearchType, pagingParameters, onComplete); }
        public EQTask TwitterFindFriends(string search, Db.SocialSearchType socialSearchType, PagingParameters pagingParameters, Action<List<Friend>, bool, EQException> onComplete) { return _api.User_TwitterFindFriends(search, socialSearchType, pagingParameters, onComplete); }

        public EQTask UpdateSocial(bool isSocialOn, int fbBits, int twitterBits, Action<User, EQException> onComplete) { return _api.User_UpdateSocial(isSocialOn, fbBits, twitterBits, onComplete); }

        public EQTask SocialAdd(string action, int? collectionId, int? contentFileId, bool force, Action<EQException> onComplete) { return _api.User_SocialAdd(action, collectionId, contentFileId, force, onComplete); }
        public EQTask SocialRemove(string action, int? collectionId, int? contentFileId, bool force, Action<EQException> onComplete) { return _api.User_SocialRemove(action, collectionId, contentFileId, force, onComplete); }
    }
}
