package post

import (
	"context"

	"time"

	"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/vars"
	"bsm/full/module/social/feed/internal/models"
	pb "bsm/full/module/social/feed/pb"
)

// 计数操作
func Action(ctx context.Context, in *pb.PostActionRequest) (reply *pb.StatusReply, err error) {
	_, err = service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}
	if in.GetActionOp() == "" || in.GetActionType() == "" || in.GetIdentity() == "" {
		return nil, errcode.ErrInvalidArgument
	}
	if err := models.LikeAction(in.ActionOp, in.ActionType, in.Identity); err != nil {
		printer.Error(err.Error())
		return nil, err
	}
	return &pb.StatusReply{
		Data:    vars.OK,
		Timeseq: time.Now().UnixNano(),
	}, nil

}
