﻿using System.Collections.Generic;
using System.Text;
using Toast.SmartDL;

public static class SmartDLUtil
{

    public static string ToString(SmartDLResult result)
    {
        return string.Format("code={0},isCompleted={1},message={2}",
            result.ResultCode, result.IsCompleted, result.ResultString);
    }

    public static string ToString(SmartDLProgressInfo progressInfo)
    {
        return string.Format(
            "Percentage: {0}, Speed: {1}, TotalReceivedBytes: {2}, TotalFileBytes: {3}, TotalFileNumber: {4}",
            progressInfo.Percentage, progressInfo.Speed,
            progressInfo.TotalReceivedBytes, progressInfo.TotalFileBytes, progressInfo.TotalFileNumber);
    }

    public static string ToString(SmartDLFileStreamInfo fileInfo)
    {
        return string.Format("ThreadId: {0}, FileName: {1}, DownloadedBytes: {2}, TotalBytes: {3}, FileNumber: {4}",
            fileInfo.ThreadId, fileInfo.FileName, fileInfo.DownloadedBytes, fileInfo.TotalBytes, fileInfo.FileNumber);
    }

    public static string ToString(Dictionary<int, SmartDLFileStreamInfo> fileMap)
    {
        if (fileMap.Count <= 0)
            return string.Empty;
        var builder = new StringBuilder();
        foreach (var kv in fileMap)
        {
            builder.AppendFormat("[{0}]={1},", kv.Key, ToString(kv.Value));
        }
        return builder.Remove(builder.Length - 1, 1).ToString();
    }
}
