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 ContentFile_ListPosts_Controller
    {
        private EQProcess _eq;

        public string Filename;
        public PagingParameters PagingParameters;

        public List<Post> Posts = new List<Post>();
        public bool? HasMore = null;

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

        public void Start(Action<EQException> onComplete)
        {
            HasMore = null;

            _eq.ContentFileService.ListPosts(Filename, PagingParameters,
                (List<Post> posts, bool hasMore, EQException ex) => // onComplete
                {
                    Posts = posts;
                    HasMore = hasMore;
                    onComplete(ex);
                }
            );
        }

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

            HasMore = null;

            PagingParameters.NextPage();

            _eq.ContentFileService.ListPosts(Filename, PagingParameters,
                (List<Post> posts, bool hasMore, EQException ex) => // onComplete
                {
                    Posts.AddRange(posts);
                    HasMore = hasMore;
                    onComplete(ex);
                }
            );
        }

    }
}
