package admin

import (
	"net/http"
	"strconv"

	"bindbox-game/internal/code"
	"bindbox-game/internal/pkg/core"
)

// GetGuildDetail 查看工会详情
// @Summary 查看工会详情
// @Description 查看指定工会详情
// @Tags 管理端.工会
// @Accept json
// @Produce json
// @Param guild_id path integer true "工会ID"
// @Success 200 {object} model.Guild
// @Failure 400 {object} code.Failure
// @Router /api/admin/guilds/{guild_id} [get]
// @Security LoginVerifyToken
func (h *handler) GetGuildDetail() core.HandlerFunc {
	return func(ctx core.Context) {
		id, err := strconv.ParseInt(ctx.Param("guild_id"), 10, 64)
		if err != nil {
			ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递工会ID"))
			return
		}
		item, err := h.guild.GetGuild(ctx.RequestContext(), id)
		if err != nil {
			ctx.AbortWithError(core.Error(http.StatusBadRequest, code.GetGuildError, err.Error()))
			return
		}
		ctx.Payload(item)
	}
}
