package com.webchat.service.message.builder;

import com.webchat.common.constants.MessageConstants;
import com.webchat.common.constants.WebConstant;
import com.webchat.common.enums.ResourceTypeEnum;
import com.webchat.domain.vo.dto.SystemMessageDTO;

import java.util.Date;

/**
 * @Author 程序员七七
 * @webSite https://www.coderutil.com
 * @Date 2022/11/13 00:24
 * @description
 */
public class SystemMessageBuilder extends AbstractMessageBuilder {

    /**
     * 构建基础系统消息
     *
     * @param type
     * @param toUserId
     * @param content
     * @return
     */
    public SystemMessageDTO build(MessageConstants.TypeEnum type,
                                  String toUserId,
                                  String content) {
        SystemMessageDTO message = new SystemMessageDTO();
        message.setCategory(getMessageCategory());
        message.setType(type.getType());
        message.setFromUserId(WebConstant.SYSTEM_USER_ID);
        message.setToUserId(toUserId);
        message.setContent(content);
        message.setCreateDate(new Date());
        return message;
    }

    /***
     * 构建有活动类系统消息
     * @param type
     * @param toUserId
     * @param content
     * @param activityName
     * @param activityUrl
     * @return
     */
    public SystemMessageDTO buildActivityMessage(MessageConstants.TypeEnum type,
                                                 String toUserId,
                                                 String content,
                                                 String activityName,
                                                 String activityUrl) {
        SystemMessageDTO message = this.build(type, toUserId, content);
        message.setActivityName(activityName);
        message.setActivityUrl(activityUrl);
        return message;
    }

    /***
     * 构建涉及资源的消息
     * @param type
     * @param toUserId
     * @param content
     * @param resourceType
     * @param resourceId
     * @return
     */
    public SystemMessageDTO buildResourceMessage(MessageConstants.TypeEnum type,
                                                 String toUserId,
                                                 String content,
                                                 ResourceTypeEnum resourceType,
                                                 String resourceId) {
        SystemMessageDTO message = this.build(type, toUserId, content);
        message.setResourceType(resourceType.getType());
        message.setResourceId(resourceId);
        return message;
    }

    @Override
    protected String getMessageCategory() {
        return MessageConstants.CategoryEnum.SYSTEM.getCategory();
    }
}
