package cn.reghao.tnb.oss.store.model.po;

import cn.reghao.jutil.jdk.web.db.BaseObject;
import cn.reghao.tnb.oss.store.util.AuthContext;
import cn.reghao.tnb.oss.api.rest.UploadFilePart;
import lombok.Getter;
import lombok.NoArgsConstructor;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

/**
 * 文件分片详情
 *
 * @author reghao
 * @date 2024-10-24 16:33:16
 */
@NoArgsConstructor
@Getter
public class FileMultipart extends BaseObject<Integer> {
    @NotBlank
    @Size(max = 255)
    private String contentId;
    @NotBlank
    @Size(max = 255)
    private String sha256sum;
    @NotBlank
    @Size(max = 255)
    private String absolutePath;
    @NotNull
    private Long totalSize;
    @NotNull
    private Integer chunkSize;
    @NotNull
    private Integer totalChunks;
    @NotNull
    private Boolean uploaded;
    @NotNull
    private Integer uploadBy;

    public FileMultipart(String contentId, UploadFilePart uploadFilePart, String absolutePath) {
        this.contentId = contentId;
        this.sha256sum = uploadFilePart.getIdentifier();
        this.absolutePath = absolutePath;
        this.totalSize = uploadFilePart.getTotalSize();
        this.chunkSize = (int)uploadFilePart.getChunkSize();
        this.totalChunks = (int)uploadFilePart.getTotalChunks();
        this.uploaded = false;
        this.uploadBy = AuthContext.getUserId();
    }
}
