package post

import (
	"context"

	"bsm/full/module/base/cms/internal/models"
	pb "bsm/full/module/base/cms/pb"
	"git.apinb.com/bsm-sdk/core/errcode"
	"git.apinb.com/bsm-sdk/core/printer"
	"git.apinb.com/bsm-sdk/core/service"
)

// 文章点踩处理
func IncrPostUnlike(ctx context.Context, in *pb.PostOpIdentityRequest) (*pb.StatusReply, error) {
	_, err := service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}

	if in.GetOpIdentity() == "" || in.GetPostIdentity() == "" {
		return nil, errcode.ErrInvalidArgument
	}
	err = models.IncrOrDescPostField(in.PostIdentity, "unlike_hits", false)
	if err != nil {
		printer.Error(err.Error())
		return nil, errcode.ErrDB
	}
	return &pb.StatusReply{}, nil
}
