package orchestrator

import (
	"context"

	"github.com/tech/sendico/pkg/payments/rail"
)

type fakeRailGateway struct {
	rail         string
	network      string
	capabilities rail.RailCapabilities
	sendFn       func(context.Context, rail.TransferRequest) (rail.RailResult, error)
	observeFn    func(context.Context, string) (rail.ObserveResult, error)
	blockFn      func(context.Context, rail.BlockRequest) (rail.RailResult, error)
	releaseFn    func(context.Context, rail.ReleaseRequest) (rail.RailResult, error)
}

func (f *fakeRailGateway) Rail() string {
	return f.rail
}

func (f *fakeRailGateway) Network() string {
	return f.network
}

func (f *fakeRailGateway) Capabilities() rail.RailCapabilities {
	return f.capabilities
}

func (f *fakeRailGateway) Send(ctx context.Context, req rail.TransferRequest) (rail.RailResult, error) {
	if f.sendFn != nil {
		return f.sendFn(ctx, req)
	}
	return rail.RailResult{ReferenceID: "transfer-1", Status: rail.TransferStatusWaiting}, nil
}

func (f *fakeRailGateway) Observe(ctx context.Context, referenceID string) (rail.ObserveResult, error) {
	if f.observeFn != nil {
		return f.observeFn(ctx, referenceID)
	}
	return rail.ObserveResult{ReferenceID: referenceID, Status: rail.TransferStatusWaiting}, nil
}

func (f *fakeRailGateway) Block(ctx context.Context, req rail.BlockRequest) (rail.RailResult, error) {
	if f.blockFn != nil {
		return f.blockFn(ctx, req)
	}
	return rail.RailResult{ReferenceID: req.IdempotencyKey, Status: rail.TransferStatusWaiting}, nil
}

func (f *fakeRailGateway) Release(ctx context.Context, req rail.ReleaseRequest) (rail.RailResult, error) {
	if f.releaseFn != nil {
		return f.releaseFn(ctx, req)
	}
	return rail.RailResult{ReferenceID: req.ReferenceID, Status: rail.TransferStatusWaiting}, nil
}
