package product

import (
	"context"
	"time"

	"bsm/full/module/ec/mall/internal/impl"
	"bsm/full/module/ec/mall/internal/models"
	pb "bsm/full/module/ec/mall/pb"
	"git.apinb.com/bsm-sdk/core/errcode"
	"git.apinb.com/bsm-sdk/core/printer"
	"git.apinb.com/bsm-sdk/core/service"
)

// Forbidden 批量操作
func ItemBatchOp(ctx context.Context, in *pb.OpRequest) (reply *pb.IdentityStatusReply, err error) {
	// parse authorization meta.
	_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
	if err != nil {
		return nil, err
	}

	if len(in.GetIdentity()) == 0 {
		return nil, errcode.ErrInvalidArgument
	}
	// TODO: add your logic code & delete this line.
	err = impl.DBService.Model(&models.MallProduct{}).Where("identity in ?", in.Identity).Update("status", in.Status).Error
	if err != nil {
		printer.Error(err.Error())
		return nil, errcode.ErrDB
	}

	return &pb.IdentityStatusReply{
		Code:    0,
		Message: "OK",
		Timeseq: time.Now().UnixMilli(),
	}, nil

}
