package orchestrator

import (
	"testing"

	"github.com/tech/sendico/payments/orchestrator/storage/model"
	mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1"
	orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
)

func TestShouldEstimateNetworkFeeSkipsCard(t *testing.T) {
	intent := &orchestratorv1.PaymentIntent{
		Kind: orchestratorv1.PaymentKind_PAYMENT_KIND_PAYOUT,
		Destination: &orchestratorv1.PaymentEndpoint{
			Endpoint: &orchestratorv1.PaymentEndpoint_Card{
				Card: &orchestratorv1.CardEndpoint{},
			},
		},
	}
	if shouldEstimateNetworkFee(intent) {
		t.Fatalf("expected network fee estimation to be skipped for card payouts")
	}
}

func TestShouldEstimateNetworkFeeManagedWallet(t *testing.T) {
	intent := &orchestratorv1.PaymentIntent{
		Destination: &orchestratorv1.PaymentEndpoint{
			Endpoint: &orchestratorv1.PaymentEndpoint_ManagedWallet{
				ManagedWallet: &orchestratorv1.ManagedWalletEndpoint{ManagedWalletRef: "mw"},
			},
		},
	}
	if !shouldEstimateNetworkFee(intent) {
		t.Fatalf("expected network fee estimation when destination is managed wallet")
	}
}

func TestMapMntxStatusToState(t *testing.T) {
	if mapMntxStatusToState(mntxv1.PayoutStatus_PAYOUT_STATUS_PROCESSED) != model.PaymentStateSettled {
		t.Fatalf("processed should map to settled")
	}
	if mapMntxStatusToState(mntxv1.PayoutStatus_PAYOUT_STATUS_FAILED) != model.PaymentStateFailed {
		t.Fatalf("failed should map to failed")
	}
	if mapMntxStatusToState(mntxv1.PayoutStatus_PAYOUT_STATUS_PENDING) != model.PaymentStateSubmitted {
		t.Fatalf("pending should map to submitted")
	}
	if mapMntxStatusToState(mntxv1.PayoutStatus_PAYOUT_STATUS_UNSPECIFIED) != model.PaymentStateUnspecified {
		t.Fatalf("unspecified should map to unspecified")
	}
}
