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

        public int CollectionId;
        public ListContentFilesContext ListContentFilesContext = new ListContentFilesContext();
        public PagingParameters PagingParameters;

        public List<ContentFile> ContentFiles = new List<ContentFile>();
        public bool? HasMore = null;

        public Collection_ListContentFiles_Controller(EQProcess eq, int collectionId)
        {
            _eq = eq;
            CollectionId = collectionId;
        }

        public void Start(Action<EQException> onComplete)
        {
            HasMore = null;
            _eq.CollectionService.ListContentFiles(CollectionId, ListContentFilesContext, PagingParameters,
                (List<ContentFile> contentFiles, bool hasMore, EQException ex) => // onComplete
                {
                    ContentFiles = contentFiles;
                    HasMore = hasMore;
                    onComplete(ex);
                }
            );
        }

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

            HasMore = null;

            PagingParameters.NextPage();

            _eq.CollectionService.ListContentFiles(CollectionId, ListContentFilesContext, PagingParameters,
                (List<ContentFile> contentFiles, bool hasMore, EQException ex) => // onComplete
                {
                    ContentFiles.AddRange(contentFiles);
                    HasMore = hasMore;
                    onComplete(ex);
                }
            );
        }

    }
}
