﻿using Unity.Ugc.Model;
using Unity.Ugc.Utils;

namespace Unity.Ugc.File
{
    public class LocalFile
    {
        /// <summary>
        /// 要存储的相对路径
        /// </summary>
        public string Path { get; set; }
        
        /// <summary>
        /// 字节数
        /// </summary>
        public long Size { get; set; }

        /// <summary>
        /// Md5哈希值
        /// </summary>
        public string Hash { get; set; }
        
        /// <summary>
        /// 文件类型
        /// </summary>
        public string ContentType { get; set; }
        
        /// <summary>
        /// 文件内容
        /// </summary>
        public byte[] Data { get; set; }

        public LocalFile(string path, byte[] data)
        {
            Path = path;
            Data = data;
            Size = data.Length;
            Hash = EncryptUtils.MD5Hash(data);
            ContentType = FileUtils.GetContentType(path);
        }

        public EntryModel ToEntryModel()
        {
            return new EntryModel()
            {
                Path = Path,
                ContentHash = Hash,
                ContentSize = Size,
                ContentType = ContentType,
            };
        }
    }
}