package com.kospo.talk.payload;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.kospo.talk.model.Talk;
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;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(name = "TalkDto", description = "채팅")
public class TalkDto {
    @Schema(name = "type", description = "채팅 타입")
    private String type;
    @Schema(name = "talkId", description = "채팅 아이디")
    private String talkId;
    @Schema(name = "closeYn", description = "종료여부")
    private Boolean closeYn;
    @Schema(name = "startYn", description = "채팅시작여부(유지보수)")
    private Boolean startYn;
    @Schema(name = "compYn", description = "처리 완료 여부")
    private boolean compYn;
    @Schema(name = "markYn", description = "마크여부")
    private Boolean markYn;
    @Schema(name = "insSabun", description = "등록자")
    private String insSabun;
    @Schema(name = "insName", description = "등록자명")
    private String insName;
    @Schema(name = "workId", description = "업무아이디")
    private String workId;
    @Schema(name = "workNm", description = "업무명")
    private String workNm;
    @Schema(name = "insDate", description = "등록일시")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS", timezone = "Asia/Seoul")
    private LocalDateTime insDate;
    @Schema(name = "message", description = "메시지")
    private String message;
    @Schema(name = "introOwner", description = "인트로 글 작성자 예로(유지보수 담당자 your 자주 찾는 질문 mine")
    private String introOwner;
//    @Schema(name = "line", description = "대화내용 라인")
//    private Integer line;
    @Schema(name = "readYn", description = "읽음 여부")
    private boolean readYn;
    @Schema(name = "unReadCnt", description = "안읽은 메시지 갯수")
    private Integer unReadCnt;
    @Schema(name = "deleteYn", description = "삭제 여부")
    private boolean deleteYn;
    @Schema(name = "ratingYn", description = "만족도 조사 여부")
    private Boolean ratingYn;
    @Schema(name = "talkMessages", description = "톡 메시지 목록")
    private TalkReceiveDto talkMessages;
    @Schema(name = "messageParams", description = "톡 메시지 파라미터")
    private TalkParamDto messageParams;
    @Schema(name = "talkMembers", description = "톡 멤버")
    private List<TalkMemberDto> talkMembers;
    @Schema(name = "work", description = "시스템 정보")
    private WorkDto work;
    @Schema(name = "lastMessage", description = "마지막 메시지")
    private String lastMessage;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS", timezone = "Asia/Seoul")
    @Schema(name = "lastMessageDate", description = "마지막 메시지 시간")
    private LocalDateTime lastMessageDate;
    @Schema(name = "tabId", description = "(사용자 화면용) 허브용 탭아이디")
    private String tabId;
    @Schema(name = "channelSabun", description = "채널소유자")
    private String channelSabun;
    @Schema(name = "result", description = "(사용자 화면용) 기타 데이터")
    private String result;
    @Schema(name = "reqId", description = "itsm 요청번호")
    private String reqId;
    @Schema(name = "force", description = "강제 상담종료")
    private Boolean force;
    @Schema(name = "gubun", description = "상담 구분")
    private int gubun;
    @Schema(name = "prevTalkId", description = "이전 톡방 아이디")
    private String prevTalkId;


    private ChangeTalk changeTalk;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    @JsonIgnoreProperties(ignoreUnknown = true)
    @Schema(name = "ChangeTalk", description = "톡 변경")
    public static class ChangeTalk {
        @Schema(name = "talkId", description = "새로운 톡 아이디")
        private String talkId;
        @Schema(name = "workId", description = "업무 변경")
        private String workId;
        @Schema(name = "sabun", description = "담당자 변경")
        private String sabun;
    }

    public static TalkDto to(Talk talk) {
        return TalkDto.builder()
                .type("")
                .talkId(talk.getTalkId())
                .closeYn(talk.getCloseYn())
                .startYn(talk.getStartYn())
                .ratingYn(talk.getRatingYn())
                .compYn(talk.getCompYn())
                .insSabun(talk.getInsSabun())
                .workId(talk.getWorkId())
                .insDate(talk.getInsDate())
                .insName(talk.getInsName())
                .reqId(talk.getReqId())
                .lastMessage(talk.getLastMessage())
                .lastMessageDate(talk.getLastMessageDate())
                .work(WorkDto.to(talk.getWork())).build();
    }

}
