using System;
using SqlSugar;

namespace MDL.Models
{
    /// <summary>
    /// 面单PDF缓存实体类，映射到数据库表
    /// </summary>
    [SugarTable("label_pdf_cache")]
    public class LabelPdfCache
    {
        /// <summary>
        /// 主键ID，自增
        /// </summary>
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public long Id { get; set; }
        
        /// <summary>
        /// 中性面单单号（唯一索引）
        /// </summary>
        [SugarColumn(Length = 50, IsNullable = false)]
        public string NeutralWaybillNumber { get; set; }
        
        /// <summary>
        /// PDF二进制字节流
        /// </summary>
        [SugarColumn(ColumnDataType = "longblob", IsNullable = true)]
        public byte[]? PdfBytes { get; set; }
        
        /// <summary>
        /// PDF实际页数
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public int? PageCount { get; set; }
        
        /// <summary>
        /// 文件大小（字节）
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public int? FileSize { get; set; }
        
        /// <summary>
        /// 原始标签URL，便于追踪和重新下载
        /// </summary>
        [SugarColumn(Length = 500, IsNullable = true)]
        public string? OriginalUrl { get; set; }
        
        /// <summary>
        /// 缓存状态：0=待处理，1=处理成功，2=处理失败，3=已失效
        /// </summary>
        [SugarColumn(IsNullable = false, DefaultValue = "0")]
        public byte Status { get; set; } = 0;
        
        /// <summary>
        /// 已重试次数，默认0
        /// </summary>
        [SugarColumn(IsNullable = false, DefaultValue = "0")]
        public int RetryCount { get; set; } = 0;
        
        /// <summary>
        /// 最后重试时间
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public DateTime? LastRetryTime { get; set; }
        
        /// <summary>
        /// 处理失败错误信息
        /// </summary>
        [SugarColumn(Length = 500, IsNullable = true)]
        public string? ErrorMessage { get; set; }
        
        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(IsNullable = false)]
        public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
        
        /// <summary>
        /// 更新时间
        /// </summary>
        [SugarColumn(IsNullable = false)]
        public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;
        
        /// <summary>
        /// 尾程跟踪单号（与订单表字段一致）
        /// </summary>
        [SugarColumn(Length = 200, IsNullable = true)]
        public string? FinalMileTrackingNumber { get; set; }
        
        /// <summary>
        /// 客户ID（与订单表字段一致，关联customers表）
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public int? CustomerId { get; set; }
        
        /// <summary>
        /// 提取到的条码单号
        /// </summary>
        [SugarColumn(Length = 200, IsNullable = true)]
        public string? BarcodeNumber { get; set; }
        
        /// <summary>
        /// 条码类型：0=未识别到，1=一维码，2=二维码
        /// </summary>
        [SugarColumn(IsNullable = false, DefaultValue = "0")]
        public byte BarcodeType { get; set; } = 0;
        
        /// <summary>
        /// 识别置信度（0-100，数值越高识别结果越可靠）
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public int? BarcodeConfidence { get; set; }
        
        /// <summary>
        /// 条码提取完成时间
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public DateTime? BarcodeExtractTime { get; set; }
        
        /// <summary>
        /// PDF解析花费的时间（毫秒）
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public int? ParseDurationMs { get; set; }
    }
}
