package payment

import (
	"context"

	"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/service"
)

// 获取支付的详情
func Get(ctx context.Context, in *pb.IdentRequest) (reply *pb.PaymentItem, err error) {
	auth, ok := service.ParseMetaCtx(ctx, nil)
	if ok != nil {
		return nil, ok
	}

	if in.Identity == "" {
		return nil, errcode.ErrInvalidArgument
	}
	paymentRecord, err := models.GetWalletPaymentByIdentity(auth.Identity, in.Identity)
	if err != nil {
		return nil, errcode.ErrNotFound(404, "payment")
	}

	return &pb.PaymentItem{
		OrderNo:    paymentRecord.OrderNo,
		TradeNo:    paymentRecord.TradeNo,
		Type:       int32(paymentRecord.Type),
		PayChannel: int32(paymentRecord.PayChannel),
		PayType:    paymentRecord.PayType,
		Amount:     paymentRecord.Amount,
		Args:       paymentRecord.Args,
		Status:     int32(paymentRecord.Status),
	}, nil
}
