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

using EQNetwork;
using EQNetwork.Objects;
using EQNetwork.Services;
using EQNetwork.Utility;

namespace EQNetwork.Controllers
{
    public class User_ListUsers_Controller
    {
        private EQProcess _eq;

        public ListUsersContext ListUsersContext = new ListUsersContext();
        public PagingParameters PagingParameters;

        public List<User> Users = new List<User>();
        public bool? HasMore = null;

        public User_ListUsers_Controller(EQProcess eq)
        {
            _eq = eq;
        }

        public void Start(Action<EQException> onComplete)
        {
            HasMore = null;
            _eq.UserService.ListUsers(ListUsersContext, PagingParameters,
                (List<User> users, bool hasMore, EQException ex) => // onComplete
                {
                    Users = users;
                    HasMore = hasMore;
                    onComplete(ex);
                }
            );
        }

        public void More(Action<EQException> onComplete)
        {
            if (HasMore == false)
                return;

            HasMore = null;

            PagingParameters.NextPage();

            _eq.UserService.ListUsers(ListUsersContext, PagingParameters,
                (List<User> users, bool hasMore, EQException ex) => // onComplete
                {
                    Users.AddRange(users);
                    HasMore = hasMore;
                    onComplete(ex);
                }
            );
        }

    }
}
