package srequest

import "testing"

func TestValidateQuoteIdempotency(t *testing.T) {
	t.Run("non-preview requires idempotency key", func(t *testing.T) {
		if err := validateQuoteIdempotency(false, ""); err == nil {
			t.Fatalf("expected error for empty idempotency key")
		}
	})

	t.Run("preview rejects idempotency key", func(t *testing.T) {
		if err := validateQuoteIdempotency(true, "idem-1"); err == nil {
			t.Fatalf("expected error when preview request has idempotency key")
		}
	})

	t.Run("preview accepts empty idempotency key", func(t *testing.T) {
		if err := validateQuoteIdempotency(true, ""); err != nil {
			t.Fatalf("expected no error, got %v", err)
		}
	})

	t.Run("non-preview accepts idempotency key", func(t *testing.T) {
		if err := validateQuoteIdempotency(false, "idem-1"); err != nil {
			t.Fatalf("expected no error, got %v", err)
		}
	})
}

func TestInitiatePaymentsValidate(t *testing.T) {
	t.Run("accepts quoteRef", func(t *testing.T) {
		req := &InitiatePayments{
			PaymentBase: PaymentBase{IdempotencyKey: "idem-1"},
			QuoteRef:    " quote-1 ",
		}
		if err := req.Validate(); err != nil {
			t.Fatalf("expected no error, got %v", err)
		}
		if got, want := req.QuoteRef, "quote-1"; got != want {
			t.Fatalf("quoteRef mismatch: got=%q want=%q", got, want)
		}
	})

	t.Run("rejects missing quoteRef", func(t *testing.T) {
		req := &InitiatePayments{
			PaymentBase: PaymentBase{IdempotencyKey: "idem-1"},
		}
		if err := req.Validate(); err == nil {
			t.Fatal("expected error")
		}
	})
}
