package psvc

import (
	"testing"

	"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/qsnap"
	"github.com/tech/sendico/payments/storage/model"
	"github.com/tech/sendico/pkg/discovery"
	paymenttypes "github.com/tech/sendico/pkg/payments/types"
)

func TestBatchOptimizationContextFromItem_UsesOperationTargetContext(t *testing.T) {
	item := qsnap.ResolvedItem{
		IntentRef: "intent-1",
		IntentSnapshot: model.PaymentIntent{
			Ref: "intent-1",
			Destination: model.PaymentEndpoint{
				Type: model.EndpointTypeCard,
				Card: &model.CardEndpoint{
					Pan:      "2200001100000001",
					ExpMonth: 1,
					ExpYear:  2030,
				},
			},
			Amount:             &paymenttypes.Money{Amount: "100", Currency: "RUB"},
			SettlementCurrency: "RUB",
		},
		QuoteSnapshot: &model.PaymentQuoteSnapshot{
			Route: &paymenttypes.QuoteRouteSpecification{
				Hops: []*paymenttypes.QuoteRouteHop{
					{Index: 1, Rail: "CRYPTO", Gateway: "gw-crypto", Network: "TRON_NILE", Role: paymenttypes.QuoteRouteHopRoleSource},
					{Index: 2, Rail: "CARD", Gateway: "mcards", Network: "TRON_NILE", Role: paymenttypes.QuoteRouteHopRoleDestination},
				},
			},
		},
	}

	ctx := batchOptimizationContextFromItem(item)
	if got, want := ctx.Rail, model.ParseRail(string(discovery.RailCardPayout)); got != want {
		t.Fatalf("operation rail mismatch: got=%q want=%q", got, want)
	}
	if got, want := ctx.Provider, "mcards"; got != want {
		t.Fatalf("provider mismatch: got=%q want=%q", got, want)
	}
	if got, want := ctx.Network, "TRON_NILE"; got != want {
		t.Fatalf("network mismatch: got=%q want=%q", got, want)
	}
}
