package health

import (
	"context"
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/stretchr/testify/assert"

	v1alpha1 "github.com/pfeifferj/container-mom-go/pkg/apis/containermom/v1alpha1"
)

// mockOperator implements the minimal interface needed for health checks
type mockOperator struct {
	// No longer needs mongodb
}

// Implement required methods with stubs
func (m *mockOperator) GetCurrentCustomer(_ context.Context) (*v1alpha1.Customer, error) {
	return nil, nil
}

func (m *mockOperator) GetResourceUsage(_ context.Context, id string) (*v1alpha1.ResourceUsage, error) {
	return nil, nil
}

func (m *mockOperator) GetBillingHistory(_ context.Context, id string) ([]*v1alpha1.BillingRecord, error) {
	return nil, nil
}

func (m *mockOperator) UpdateBillingPlan(ctx context.Context, id, plan string) error {
	return nil
}

func (m *mockOperator) UpdateBillingStatus(ctx context.Context, id string, status v1alpha1.BillingStatus) error {
	return nil
}

func TestHealthChecks(t *testing.T) {
	mockOp := &mockOperator{}
	handler := &Handler{Operator: mockOp}

	t.Run("healthz", func(t *testing.T) {
		req := httptest.NewRequest(http.MethodGet, "/healthz", nil)
		w := httptest.NewRecorder()

		handler.Healthz(w, req)

		assert.Equal(t, http.StatusOK, w.Code)
	})

	t.Run("readyz", func(t *testing.T) {
		req := httptest.NewRequest(http.MethodGet, "/readyz", nil)
		w := httptest.NewRecorder()

		handler.Readyz(w, req)

		// Should succeed now that we don't check MongoDB
		assert.Equal(t, http.StatusOK, w.Code)
	})
}
