package ping

import (
	"context"

	"apps/backend/internal/svc"
	"apps/backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HealthLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHealthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HealthLogic {
	return &HealthLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}

func (l *HealthLogic) Health() (resp *types.HealthData, err error) {
	if err := redisHealth(l.ctx, l.svcCtx); err != nil {
		l.Errorf("health redis check failed: %v", err)
		return nil, err
	}
	return &types.HealthData{Status: "ok", Service: "haixun-gateway"}, nil
}
