package post

import (
	"context"

	"git.apinb.com/bsm-sdk/core/errcode"
	"git.apinb.com/bsm-sdk/core/service"

	"bsm/full/module/base/cms/internal/models"
	pb "bsm/full/module/base/cms/pb"
)

// DescCommentUnlike 减少评论踩
func DescCommentUnlike(ctx context.Context, in *pb.CommentOpIdentityRequest) (*pb.StatusReply, error) {
	_, err := service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}

	if in.GetCommentIdentity() == "" || in.GetOpIdentity() == "" {
		return nil, errcode.ErrInvalidArgument
	}

	err = models.IncrOrDescCommentField(in.CommentIdentity, "unlike_hits", true)
	if err != nil {
		return nil, errcode.ErrDB
	}

	return &pb.StatusReply{}, nil
}
