package basic

import (
	"context"
	"time"

	"bsm/full/module/finance/wallet/internal/impl"
	"bsm/full/module/finance/wallet/internal/models"
	pb "bsm/full/module/finance/wallet/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/vars"
)

// 删除银行卡
func RmBankCard(ctx context.Context, in *pb.RmBankCardRequest) (reply *pb.StatusReply, err error) {
	auth, ok := service.ParseMetaCtx(ctx, nil)
	if ok != nil {
		return nil, ok
	}

	if in.Identity == "" {
		return nil, errcode.ErrInvalidArgument
	}

	err = impl.DBService.Where("passport_identity=? and identity=?", auth.Identity, in.Identity).Delete(&models.WalletBank{}).Error
	if err != nil {
		printer.Error(err.Error())
		return nil, errcode.ErrDB
	}

	return &pb.StatusReply{
		Message: vars.OK,
		Timeseq: time.Now().UnixMilli(),
	}, nil
}
