package com.microservices.file.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.microservices.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;

/**
 * 文件分片上传会话对象 sys_file_upload_session
 *
 * @author microservices
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel("文件分片上传会话")
public class FileUploadSession extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 会话ID
     */
    @ApiModelProperty(value = "会话ID")
    private Long sessionId;

    /**
     * 上传ID（唯一标识）
     */
    @ApiModelProperty(value = "上传ID（唯一标识）")
    private String uploadId;

    /**
     * 文件ID（关联sys_file_info表）
     */
    @ApiModelProperty(value = "文件ID（关联sys_file_info表）")
    private Long fileId;

    /**
     * 原始文件名
     */
    @ApiModelProperty(value = "原始文件名")
    private String fileName;

    /**
     * 文件总大小（字节）
     */
    @ApiModelProperty(value = "文件总大小（字节）")
    private Long fileSize;

    /**
     * 文件签名（用于秒传校验）
     * - FULL 类型：完整文件的 MD5 值
     * - SAMPLE 类型：采样点哈希值
     */
    @ApiModelProperty(value = "文件签名（用于秒传校验，可能是完整MD5或采样点哈希）")
    private String fileSignature;

    /**
     * 分片大小（字节）
     */
    @ApiModelProperty(value = "分片大小（字节）")
    private Long chunkSize;

    /**
     * 总分片数
     */
    @ApiModelProperty(value = "总分片数")
    private Integer totalChunks;

    /**
     * 已上传分片数
     */
    @ApiModelProperty(value = "已上传分片数")
    private Integer uploadedChunks;

    /**
     * 上传类型（cms/dms/resource/pms等）
     */
    @ApiModelProperty(value = "上传类型（cms/dms/resource/pms等）")
    private String uploadType;

    /**
     * 层级路径
     */
    @ApiModelProperty(value = "层级路径")
    private String hierarchy;

    /**
     * 状态：INIT-初始化，UPLOADING-上传中，MERGING-合并中，COMPLETED-已完成，FAILED-失败，MERGE_FAILED-合并失败
     */
    @ApiModelProperty(value = "状态：INIT-初始化，UPLOADING-上传中，MERGING-合并中，COMPLETED-已完成，FAILED-失败，MERGE_FAILED-合并失败")
    private String status;

    /**
     * 临时文件存储路径
     */
    @ApiModelProperty(value = "临时文件存储路径")
    private String tempFilePath;

    /**
     * 错误信息
     */
    @ApiModelProperty(value = "错误信息")
    private String errorMessage;

    /**
     * 过期时间（24小时）
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "过期时间（24小时）")
    private Date expireTime;

    /**
     * 哈希类型：FULL=完整文件MD5, SAMPLE=采样点哈希
     */
    @ApiModelProperty(value = "哈希类型：FULL=完整文件MD5, SAMPLE=采样点哈希")
    private String hashType;

    /**
     * 采样点分片序号列表（逗号分隔，仅SAMPLE类型）
     */
    @ApiModelProperty(value = "采样点分片序号列表")
    private String sampleChunks;

    /**
     * 上传状态枚举
     */
    public enum Status {
        INIT("INIT", "初始化"),
        UPLOADING("UPLOADING", "上传中"),
        MERGING("MERGING", "合并中"),
        COMPLETED("COMPLETED", "已完成"),
        FAILED("FAILED", "失败"),
        MERGE_FAILED("MERGE_FAILED", "合并失败");

        private final String code;
        private final String desc;

        Status(String code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public String getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }
}
