package com.microservices.file.domain.vo.response;

import com.microservices.file.domain.vo.UploadProgressVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 上传进度响应
 *
 * @author microservices
 */
@Data
@ApiModel("上传进度响应")
public class UploadProgressResponseVo implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("上传ID")
    private String uploadId;

    @ApiModelProperty("文件名")
    private String fileName;

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

    @ApiModelProperty("总分片数")
    private Integer totalChunks;

    @ApiModelProperty("已上传分片数")
    private Integer uploadedChunks;

    @ApiModelProperty("上传进度（百分比）")
    private Integer progress;

    @ApiModelProperty("上传状态")
    private String status;

    @ApiModelProperty("上传速度（字节/秒）")
    private Long uploadSpeed;

    @ApiModelProperty("预计剩余时间（秒）")
    private Long remainingSeconds;

    @ApiModelProperty("合并进度（0-100，仅在MERGING状态时有效）")
    private Integer mergeProgress;

    @ApiModelProperty("文件ID（合并完成后返回）")
    private Long fileId;

    @ApiModelProperty("文件下载地址（合并完成后返回）")
    private String downloadUrl;

    @ApiModelProperty("文件路径（合并完成后返回）")
    private String filePath;

    @ApiModelProperty("错误信息（合并失败时返回）")
    private String errorMessage;

    /**
     * 从UploadProgressVo转换
     */
    public static UploadProgressResponseVo from(UploadProgressVo vo) {
        UploadProgressResponseVo response = new UploadProgressResponseVo();
        response.setUploadId(vo.getUploadId());
        response.setFileName(vo.getFileName());
        response.setFileSize(vo.getFileSize());
        response.setTotalChunks(vo.getTotalChunks());
        response.setUploadedChunks(vo.getUploadedChunks());
        response.setProgress(vo.getProgress());
        response.setStatus(vo.getStatus());
        response.setUploadSpeed(vo.getUploadSpeed());
        response.setRemainingSeconds(vo.getRemainingSeconds());
        response.setMergeProgress(vo.getMergeProgress());
        response.setFileId(vo.getFileId());
        response.setDownloadUrl(vo.getDownloadUrl());
        response.setFilePath(vo.getFilePath());
        response.setErrorMessage(vo.getErrorMessage());
        return response;
    }
}
