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
    {
        private EQProcess _eq;
        public UserService(EQProcess eq)
        {
            _eq = eq;
        }

        private IEQApiService _api { get { return _eq.EQApiService; } }

        public User Get(int userId) { return _api.User_Get(userId); }
        public User Get(string username) { return _api.User_Get(username); }
        public User Get() { return _api.User_Get(); }

        public Session Create(ref User user) 
        { 
            _api.User_Create(ref user);
            return _api.Session_Create(user.Username, user.Password);
        }

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

        public void Delete() { _api.User_Delete(); }
        public void Delete(User user) { _api.User_Delete(user); }
        public void Delete(int userId) { _api.User_Delete(userId); }

        public string EmailAccounts(string email) { return _api.User_EmailAccounts(email); }

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

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

        public void RequestPasswordReset(string username) { _api.User_RequestPasswordReset(username); }
        public void ResendConfirmationEmail() { _api.User_ResendConfirmationEmail(); }
        public void ResetPassword(Guid passwordResetGuid, string password) { _api.User_ResetPassword(passwordResetGuid, password); }

        public PurchaseTransaction Purchase(PurchaseContext purchaseContext) { return _api.User_Purchase(purchaseContext); }

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

        public User UpdateSocial(bool isSocialOn, int fbBits, int twitterBits) { return _api.User_UpdateSocial(isSocialOn, fbBits, twitterBits); }

        public void SocialAdd(string action, int? collectionId, int? contentFileId, bool force) { _api.User_SocialAdd(action, collectionId, contentFileId, force); }
        public void SocialRemove(string action, int? collectionId, int? contentFileId, bool force) { _api.User_SocialRemove(action, collectionId, contentFileId, force); }
    }
}
