package model

import (
	"fmt"

	"github.com/tech/sendico/pkg/merrors"
	"go.mongodb.org/mongo-driver/v2/bson"
)

type WalletPaymentData struct {
	WalletID string `bson:"walletId" json:"walletId"`
}

func (m *PaymentMethod) AsWallet() (*WalletPaymentData, error) {
	if m.Type != PaymentTypeWallet {
		return nil, merrors.InvalidArgument(fmt.Sprintf("payment method type is %s, not wallet", m.Type), "type")
	}

	var d WalletPaymentData
	if err := bson.Unmarshal(m.Data, &d); err != nil {
		return nil, err
	}

	return &d, nil
}
