package usecase

import (
	"context"
	"testing"

	"github.com/gofrs/uuid/v5"
	"github.com/saveinmed/backend-go/internal/domain"
)

func TestUpsertAndGetPaymentGatewayConfig(t *testing.T) {
	svc, _ := newTestService()
	ctx := context.Background()

	config := &domain.PaymentGatewayConfig{
		Provider:    "stripe",
		Active:      true,
		Credentials: "{\"secret\":\"secret\"}",
		Environment: "sandbox",
		Commission:  2.9,
	}

	if err := svc.UpsertPaymentGatewayConfig(ctx, config); err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	stored, err := svc.GetPaymentGatewayConfig(ctx, "stripe")
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if stored == nil || stored.Provider != "stripe" {
		t.Fatal("expected stored config to be returned")
	}
}

func TestOnboardSellerStoresAccount(t *testing.T) {
	svc, repo := newTestService()
	ctx := context.Background()

	sellerID := uuid.Must(uuid.NewV7())
	link, err := svc.OnboardSeller(ctx, sellerID, "stripe")
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if link == "" {
		t.Fatal("expected onboarding link")
	}

	stored, _ := repo.GetSellerPaymentAccount(ctx, sellerID)
	if stored == nil || stored.Status != "pending" {
		t.Fatal("expected seller payment account to be stored as pending")
	}
}
