package com.izouma.jmrh.dto;

import com.izouma.jmrh.domain.Contact;
import com.izouma.jmrh.domain.Conversation;
import com.izouma.jmrh.domain.OrgInfo;
import com.izouma.jmrh.domain.User;
import com.izouma.jmrh.enums.ConversationType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ConversationDTO {
    private Long id;

    private String sessionId;

    private Long userId;

    private Long toUserId;

    private Long orgId;

    private Contact contact;

    private ConversationType type;

    private LocalDateTime lastUpdate;

    private String lastMessage;

    private OrgInfo orgInfo;

    private String title;

    private String icon;

    private long unread;

    public ConversationDTO(Conversation conversation, long unread, OrgInfo orgInfo, User to) {
        BeanUtils.copyProperties(conversation, this);
        this.unread = unread;
        this.orgInfo = orgInfo;
        switch (type) {
            case DOCKING:
                title = orgInfo.getOrgName();
                icon = StringUtils.isEmpty(orgInfo.getLogo())
                        ? "https://jxjmrh.oss-cn-hangzhou.aliyuncs.com/image/2021-03-04-17-34-09WoHLRdSP.png"
                        : orgInfo.getLogo();
                break;
            case PUBLISH:
                title = to.getNickname();
                icon = to.getAvatar();
                break;
            case SYS:
                title = "系统消息";
                icon = "https://jxjmrh.oss-cn-hangzhou.aliyuncs.com/application/icon/conversation_icon_sys.png";
                break;
            case LIKE:
                title = "点赞";
                icon = "https://jxjmrh.oss-cn-hangzhou.aliyuncs.com/application/icon/conversation_icon_like.png";
                break;
            case COMMENT:
                title = "回复";
                icon = "https://jxjmrh.oss-cn-hangzhou.aliyuncs.com/application/icon/conversation_icon_comment.png";
                break;
        }
    }
}
