package user

import (
	"net/http"

	"code.gitea.io/gitea/modules/context"
	"code.gitea.io/gitea/modules/timeutil"
	hat_activities_models "code.gitlink.org.cn/Gitlink/gitea_hat.git/models/activities"
)

func GetUserHeatmapData(ctx *context.APIContext) {
	startAt := timeutil.TimeStamp(ctx.FormInt("start"))
	endAt := timeutil.TimeStamp(ctx.FormInt("end"))
	if startAt <= 0 || endAt <= 0 {
		startAt = timeutil.TimeStampNow() - 31536000
		endAt = timeutil.TimeStampNow()
	}

	heatmap, err := hat_activities_models.GetUserHeatmapDataByTimestampRange(ctx.ContextUser, nil, ctx.Doer, startAt, endAt)
	if err != nil {
		ctx.Error(http.StatusInternalServerError, "GetUserHeatmapDataByTimestampRange", err)
		return
	}

	ctx.JSON(http.StatusOK, heatmap)

}
