package cn.reghao.tnb.message.app.model.po;

import cn.reghao.jutil.jdk.web.db.BaseObject;
import cn.reghao.tnb.message.api.constant.MsgType;
import cn.reghao.tnb.message.api.dto.UserMessageDto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * @author reghao
 * @date 2024-03-28 22:11:47
 */
@NoArgsConstructor
@AllArgsConstructor
@Setter
@Getter
public class UserMessage extends BaseObject<Integer> {
    @NotNull
    private Integer msgType;
    @NotNull
    private Long messageId;
    @NotBlank
    @Size(min = 1, max = 64)
    private String title;
    @NotBlank
    @Size(min = 1, max = 255)
    private String content;
    @NotNull
    private Boolean unread;
    @NotNull
    private Long userId;
    @NotNull
    private LocalDateTime createAt;

    public UserMessage(Long messageId, UserMessageDto userMessageDto) {
        this.msgType = userMessageDto.getMsgType();
        this.messageId = messageId;
        this.title = userMessageDto.getTitle();
        this.content = userMessageDto.getContent();
        this.unread = true;
        this.userId = userMessageDto.getReceiver();
        this.createAt = LocalDateTime.now();
    }
}
