// Filename: internal/domain/upstream/module.go
package upstream

import (
	"gemini-balancer/internal/models"

	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

type Module struct {
	service *Service
	handler *Handler
}

func NewModule(db *gorm.DB) *Module {
	service := NewService(db)
	handler := NewHandler(service)

	return &Module{
		service: service,
		handler: handler,
	}
}

// === 领域暴露的公共API ===

// SelectActiveWeighted

func (m *Module) SelectActiveWeighted(upstreams []*models.UpstreamEndpoint) (*models.UpstreamEndpoint, error) {
	return m.service.SelectActiveWeighted(upstreams)
}

func (m *Module) RegisterRoutes(router *gin.RouterGroup) {
	m.handler.RegisterRoutes(router)
}
