package idem

import (
	"context"

	"github.com/tech/sendico/payments/storage"
	"github.com/tech/sendico/payments/storage/model"
	"go.mongodb.org/mongo-driver/v2/bson"
)

type fakeStore struct {
	createFn              func(ctx context.Context, payment *model.Payment) error
	getByIdempotencyKeyFn func(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.Payment, error)
}

func (f *fakeStore) Create(ctx context.Context, payment *model.Payment) error {
	if f.createFn == nil {
		return nil
	}
	return f.createFn(ctx, payment)
}

func (f *fakeStore) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.Payment, error) {
	if f.getByIdempotencyKeyFn == nil {
		return nil, storage.ErrPaymentNotFound
	}
	return f.getByIdempotencyKeyFn(ctx, orgRef, idempotencyKey)
}
