package com.kospo.talk.payload;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.kospo.talk.model.TalkMessage;
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 = "TalkMessageDto", description = "채팅 내용")
public class TalkMessageDto {
    @Schema(name = "talkId", description = "채팅 아이디")
    private String talkId;
    @Schema(name = "sabun", description = "사번")
    private String sabun;
    @Schema(name = "message", description = "내용")
    private String message;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS", timezone = "Asia/Seoul")
    @Schema(name = "insDate", description = "등록일")
    private LocalDateTime insDate;
    @Schema(name = "insName", description = "등록자")
    private String insName;

    public static TalkMessageDto to(TalkMessage talkContent) {
        return TalkMessageDto.builder()
                .talkId(talkContent.getId().getTalkId())
                .sabun(talkContent.getId().getSabun())
                .message(talkContent.getMessage())
                .insDate(talkContent.getId().getInsDate())
                .insName(talkContent.getInsName()).build();
    }
}
