package app

import (
	"google.golang.org/grpc"
	"hyapp/pkg/grpchealth"
	"hyapp/pkg/healthhttp"
	servicehealth "hyapp/pkg/servicekit/health"
	"hyapp/services/activity-service/internal/config"
	mysqlstorage "hyapp/services/activity-service/internal/storage/mysql"
)

func newHealthServers(cfg config.Config, server *grpc.Server, repository *mysqlstorage.Repository) (*grpchealth.ServingChecker, *healthhttp.Server, error) {
	// gRPC health 和 HTTP ready 共用同一个 checker，避免一个入口显示 ready、另一个入口还在 draining。
	return servicehealth.New(server, servicehealth.Config{
		ServiceName: "activity-service",
		HTTPAddr:    cfg.HealthHTTPAddr,
		NodeID:      cfg.NodeID,
		Dependencies: []grpchealth.Dependency{{
			Name:  "mysql",
			Check: repository.Ping,
		}},
	})
}
