using System;
using System.Collections.Generic;

namespace hirdParty.DownloadSystem
{
    [Serializable]
    public class AssetMD5Info
    {
        public List<MD5FileInfo> fileInfo;

        public void Deduplication()
        {
            if (fileInfo == null)
            {
                return;
            }

            List<string> allName = new List<string>();
            for (int i = 0; i < fileInfo.Count; i++)
            {
                string n = fileInfo[i].fileName;
                if (allName.Contains(n))
                {
                    fileInfo.RemoveAt(i);
                    i--;
                }

                allName.Add(n);
            }
        }

        public void Sort()
        {
            if (fileInfo == null)
            {
                return;
            }

            fileInfo.Sort(Stot);
        }

        private int Stot(MD5FileInfo a, MD5FileInfo b)
        {
            if (a.size > b.size)
            {
                return 1;
            }
            else if (a.size < b.size)
            {
                return -1;
            }

            return 0;
        }

        public AssetMD5Info(List<MD5FileInfo> a)
        {
            this.fileInfo = a;
        }
    }

    [Serializable]
    public class MD5FileInfo
    {
        public string fileName;
        public string md5;
        public long size;
    }
}