package com.kospo.talk.payload;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.kospo.talk.model.TalkAttach;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(name = "AttachDto", description = "채팅 첨부파일")
public class AttachDto {
    @Schema(name = "key", description = "첨부파일업로드키")
    private String key;
    @Schema(name = "talkId", description = "채팅아이디")
    private String talkId;
    @Schema(name = "sabun", description = "사번")
    private String sabun;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS", timezone = "Asia/Seoul")
    @Schema(name = "insDate", description = "등록일")
    private LocalDateTime insDate;
    @Schema(name = "sort", description = "정렬")
    private Integer sort;
    @Schema(name = "onm", description = "논리명")
    private String onm;
    @Schema(name = "vnm", description = "물리명")
    private String vnm;
    @Schema(name = "path", description = "경로")
    private String path;
    @Schema(name = "type", description = "파일 종류")
    private String type;
    @Schema(name = "size", description = "파일 용량")
    private long size;
    @Schema(name = "totalSize", description = "(다중)파일 전체 용량")
    private long totalSize;
    @Schema(name = "data", description = "binary 데이터")
    private byte[] data;
    @Schema(name = "percent", description = "진행률")
    private String percent;

    public static AttachDto to(TalkAttach talkAttach) {
        return AttachDto.builder()
                .talkId(talkAttach.getId().getTalkId())
                .sabun(talkAttach.getId().getSabun())
                .insDate(talkAttach.getId().getInsDate())
                .sort(talkAttach.getId().getSort())
                .onm(talkAttach.getOnm())
                .vnm(talkAttach.getVnm())
                .path(talkAttach.getPath())
                .size(talkAttach.getSize())
                .type(talkAttach.getType()).build();
    }
}
