package cn.reghao.tnb.content.app.vod.model.po;

import cn.reghao.jutil.jdk.db.BaseObject;
import cn.reghao.tnb.common.auth.UserContext;
import cn.reghao.tnb.content.api.dto.comment.CommentData;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

/**
 * @author reghao
 * @date 2023-02-01 16:15:43
 */
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@Setter
@Getter
public class UserComment extends BaseObject<String> {
    private Long pCommentId;
    private Long commentId;
    private String content;
    private String imgSrc;
    private List<String> commentImages;
    private Integer likes;
    private Boolean liked;
    private Integer postType;
    private String postId;
    private Long avId;
    private String location;
    private Long publishAt;
    private Long publishBy;

    public UserComment(long parentId, long commentId, CommentData commentData) {
        this.commentId = commentId;
        this.postId = commentData.getPostId();
        this.pCommentId = parentId;
        this.content = commentData.getContent();
        this.commentImages = commentData.getImageUrls();
        this.likes = commentData.getLikes();
        this.liked = false;
        this.location = commentData.getLocation();
        this.publishAt = commentData.getCreateAt();
        this.publishBy = Long.parseLong(commentData.getUser().getUserId());
    }

    public UserComment(long commentId, CommentData commentData, long parentId) {
        this.postId = commentData.getPostId();
        this.avId = 0L;
        this.pCommentId = parentId;
        this.commentId = commentId;
        this.content = commentData.getContent();
        this.commentImages = commentData.getImageUrls();
        this.likes = 0;
        this.liked = false;
        this.publishAt = System.currentTimeMillis();
        this.publishBy = UserContext.getUser();
    }
}
