
using Microsoft.AspNetCore.Http;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.ComponentModel.DataAnnotations;
using System.IO;
using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;

namespace TEAMModelOS.SDK.Module.AzureBlob.Container
{
    
    public class AzureBlobModel : TableEntity
    {


        public AzureBlobModel()
        {
            long time = DateTime.Now.ToUniversalTime().Ticks - 621355968000000000;
            Timestamp = DateTimeHelper.ConvertToDateTime(time);
        }

        public AzureBlobModel(IFormFile f, string Container ,string groupName ,string newName)
        {
            long time= DateTime.Now.ToUniversalTime().Ticks - 621355968000000000;
            ContentType = f.ContentType;
            ContentDisposition = f.ContentDisposition;
            FileName = f.FileName;
            // Headers = f.Headers.Values;
            RealName =  groupName + "/"+ newName;
            Folder = groupName;
            Length = f.Length;
            Name = f.Name;
            UploadTime = time;
            PartitionKey = Container;
            RowKey = Guid.NewGuid().ToString();
            Extension = f.FileName.Substring(f.FileName.LastIndexOf(".") + 1, (f.FileName.Length - f.FileName.LastIndexOf(".") - 1)); //扩展名
            Timestamp = DateTimeHelper.ConvertToDateTime(time);
        }

        public AzureBlobModel(FileInfo f, string Container, string groupName, string newName ,string  contentType)
        {
            long time = DateTime.Now.ToUniversalTime().Ticks - 621355968000000000;
            ContentType = contentType;
            ContentDisposition = "form-data; name=\"file\"; filename=\"" + f.Name + "\"";
            FileName = f.Name;
            // Headers = f.Headers.Values;
            RealName = groupName + "/" + newName;
            Folder = groupName;
            Length = f.Length;
            Name = "file";
            UploadTime = time;
            PartitionKey = Container;
            RowKey = Guid.NewGuid().ToString();
            Extension = f.Name.Substring(f.Name.LastIndexOf(".") + 1, (f.Name.Length - f.Name.LastIndexOf(".") - 1)); //扩展名
            Timestamp = DateTimeHelper.ConvertToDateTime(time);
        }

        public AzureBlobModel(string fileName, string Container, string groupName, string newName, string contentType ,long length)
        {
            long time = DateTime.Now.ToUniversalTime().Ticks - 621355968000000000;
            ContentType = contentType;
            ContentDisposition = "form-data; name=\"file\"; filename=\"" + fileName + "\"";
            FileName = fileName;
            // Headers = f.Headers.Values;
            RealName = groupName + "/" + newName;
            Folder = groupName;
            Length = length;
            Name = "file";
            UploadTime = time;
            PartitionKey = Container;
            RowKey = Guid.NewGuid().ToString();
            Extension = fileName.Substring(fileName.LastIndexOf(".") + 1, (fileName.Length - fileName.LastIndexOf(".") - 1)); //扩展名
            Timestamp = DateTimeHelper.ConvertToDateTime(time);
        }
        public AzureBlobModel(string fileName, string Container, string groupName, string newName,string sha1Code, string contentType, long length)
        {
            long time = DateTime.Now.ToUniversalTime().Ticks - 621355968000000000;
            ContentType = contentType;
            ContentDisposition = "form-data; name=\"file\"; filename=\"" + fileName + "\"";
            FileName = fileName;
            // Headers = f.Headers.Values;
            Sha1Code = sha1Code;
            RealName = groupName + "/" + newName;
            Folder = groupName;
            Length = length;
            Name = "file";
            UploadTime = time;
            PartitionKey = Container;
            RowKey = Guid.NewGuid().ToString();
            Extension = fileName.Substring(fileName.LastIndexOf(".") + 1, (fileName.Length - fileName.LastIndexOf(".") - 1)); //扩展名
            Timestamp = DateTimeHelper.ConvertToDateTime(time);
        }
        [Required(ErrorMessage = "{0} 必须填写")]
        public string Folder { get; set; }
        [Required(ErrorMessage = "{0} 必须填写")]
        public string Sha1Code { get; set; }
        //
        // 摘要:
        //     Gets the raw Content-Type header of the uploaded file.
        [Required(ErrorMessage = "{0} 必须填写")]
        public string BlobUrl { get; set; }

        //
        // 摘要:
        //     Gets the raw Content-Type header of the uploaded file.
        [Required(ErrorMessage = "{0} 必须填写")]
        public string ContentType { get; set; }
        //
        // 摘要:
        //     Gets the raw Content-Disposition header of the uploaded file.
        [Required(ErrorMessage = "{0} 必须填写")]
        public string ContentDisposition { get; set; }
        //
        // 摘要:
        //     Gets the header dictionary of the uploaded file.
        //  public IHeaderDictionary Headers { get; set; }
        //
        // 摘要:
        //     Gets the file length in bytes.
        [Required(ErrorMessage = "{0} 必须填写")]
        public long Length { get; set; }
        //
        // 摘要:
        //     Gets the form field name from the Content-Disposition header.
        [Required(ErrorMessage = "{0} 必须填写")]
        public string Name { get; set; }
        //
        // 摘要:
        //     Gets the file name from the Content-Disposition header.
        [Required(ErrorMessage = "{0} 必须填写")]
        public string FileName { get; set; }
        [Required(ErrorMessage = "{0} 必须填写")]
        public string RealName { get; set; }
        //上传时间戳
        [Required(ErrorMessage = "{0} 必须填写")]
        public long UploadTime { get; set; }
        //上传扩展文件
        [Required(ErrorMessage = "{0} 必须填写")]
        public string Extension { get; set; }
    }
}
