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 = "TalkAttachDto", description = "채팅 첨부파일")
public class TalkAttachDto {
    @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 = "uploading", description = "첨부파일 업로드 여부")
    private Boolean uploading;
    @Schema(name = "delYn", description = "첨부파일 삭제 여부")
    private Boolean delYn;
    @Schema(name = "data", description = "base64 데이터")
    private String data;

    public static TalkAttachDto to(TalkAttach talkAttach) {
        return TalkAttachDto.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())
                .uploading(talkAttach.getUploading())
                .delYn(talkAttach.getDelYn())
                .type(talkAttach.getType()).build();
    }
}
