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_chunk
 *
 * @author microservices
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel("文件分片记录")
public class FileUploadChunk extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 分片ID
     */
    @ApiModelProperty(value = "分片ID")
    private Long chunkId;

    /**
     * 上传ID
     */
    @ApiModelProperty(value = "上传ID")
    private String uploadId;

    /**
     * 分片序号（从0开始）
     */
    @ApiModelProperty(value = "分片序号（从0开始）")
    private Integer chunkNumber;

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

    /**
     * 分片文件存储路径
     */
    @ApiModelProperty(value = "分片文件存储路径")
    private String chunkPath;

    /**
     * 状态：PENDING-待上传，UPLOADED-已上传，MERGED-已合并
     */
    @ApiModelProperty(value = "状态：PENDING-待上传，UPLOADED-已上传，MERGED-已合并")
    private String status;

    /**
     * 上传时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "上传时间")
    private Date uploadTime;

    /**
     * 分片状态枚举
     */
    public enum Status {
        PENDING("PENDING", "待上传"),
        UPLOADED("UPLOADED", "已上传"),
        MERGED("MERGED", "已合并");

        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;
        }
    }
}
