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

using EQNetwork.Utility;
using EQNetwork.Aspects;

namespace EQNetwork.Objects
{
    /// <summary>
    /// The response for Upload_ListUpload is a collection of these objects which tells us which chunks to upload
    /// </summary>
    public class UploadChunk
    {
        // the following fields are returned my many of the upload api calls

//        public int? UploadChunkId { get; set; } shows up in backend code... but don't see it ever getting passed

        // properties set by backend
        public long? ChunkOffset { get; private set; }
        public long? ChunkSize { get; private set; }

        // properties used by Upload_Controller

        private DateTime? _uploadStartedTime;
        private bool? _uploadStarted;
        public bool? UploadStarted {
            get { return _uploadStarted; }
            set 
            {
                _uploadStarted = value;
                _uploadStartedTime = DateTime.Now;
            }
        }

        private DateTime? _uploadFinishedTime;
        private bool? _uploadFinished;
        public bool? UploadFinished
        {
            get { return _uploadFinished; }
            set
            {
                _uploadFinished = value;
                _uploadFinishedTime = DateTime.Now;
            }
        }

        public TimeSpan? UploadDuration
        {
            get
            {
                if (_uploadStartedTime == null) return null;
                if (_uploadFinishedTime == null) return DateTime.Now - _uploadStartedTime;
                return _uploadFinishedTime - _uploadStartedTime;
            }
        }

        public UploadChunk()
        {
        }

        public UploadChunk(XmlNode node)
        {
            EQParse.SetPropertiesWithXmlAttributes(this, node);
        }

        public override string ToString()
        {
            return " (" + ChunkOffset + " for " + ChunkSize + ")";
        }

    }
}
