package ru.soune.nocopy.dto.file;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import ru.soune.nocopy.entity.file.FileUploadSession;
import ru.soune.nocopy.entity.file.UploadStatus;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UploadProgressResponse {

    private String uploadId;
    private String fileName;
    private Integer totalChunks;
    private Integer uploadedChunks;
    private UploadStatus status;
    private Integer progressPercentage;
    private String filePath;

    public static UploadProgressResponse fromSession(FileUploadSession session) {
        int progress = session.getTotalChunks() == 0 ? 0 :
                (session.getChunksUploaded() * 100) / session.getTotalChunks();

        return UploadProgressResponse.builder()
                .uploadId(session.getUploadId())
                .fileName(session.getFileName())
                .totalChunks(session.getTotalChunks())
                .uploadedChunks(session.getChunksUploaded())
                .status(session.getStatus())
                .progressPercentage(progress)
                .filePath(session.getFilePath())
                .build();
    }
}