package post

import (
	"context"

	"time"

	"bsm/full/module/social/feed/internal/models"
	pb "bsm/full/module/social/feed/pb"
	"git.apinb.com/bsm-sdk/core/errcode"
	"git.apinb.com/bsm-sdk/core/printer"
	"git.apinb.com/bsm-sdk/core/service"
	"git.apinb.com/bsm-sdk/core/types"
	"git.apinb.com/bsm-sdk/core/utils"
)

// 新建评论
func AddComment(ctx context.Context, in *pb.CommentItem) (reply *pb.DataStatusReply, err error) {
	auth, err := service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}
	var data = &models.FeedComment{
		Std_IICUDS:   types.Std_IICUDS{Identity: utils.UUID()},
		PostIdentity: in.PostIdentity,
		Content:      in.Content,
	}
	if in.Identity != "" {
		data.ParentIdentity = in.Identity
	}
	if err := models.AddComment(data, auth.Identity); err != nil {
		printer.Error(err.Error())
		return nil, errcode.ErrDB
	}
	return &pb.DataStatusReply{
		Data:    data.Identity,
		Timeseq: time.Now().UnixNano(),
	}, nil

}
