package admin

import (
	"net/http"
	"strconv"

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

type deleteGuildResponse struct {
	Message string `json:"message"`
}

// DeleteGuild 删除工会
// @Summary 删除工会
// @Description 删除指定工会
// @Tags 管理端.工会
// @Accept json
// @Produce json
// @Param guild_id path integer true "工会ID"
// @Success 200 {object} deleteGuildResponse
// @Failure 400 {object} code.Failure
// @Router /api/admin/guilds/{guild_id} [delete]
// @Security LoginVerifyToken
func (h *handler) DeleteGuild() core.HandlerFunc {
	return func(ctx core.Context) {
		res := new(deleteGuildResponse)
		if ctx.SessionUserInfo().IsSuper != 1 {
			ctx.AbortWithError(core.Error(http.StatusBadRequest, code.DeleteGuildError, "禁止操作"))
			return
		}
		id, err := strconv.ParseInt(ctx.Param("guild_id"), 10, 64)
		if err != nil {
			ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递工会ID"))
			return
		}
		if err := h.guild.DeleteGuild(ctx.RequestContext(), id); err != nil {
			ctx.AbortWithError(core.Error(http.StatusBadRequest, code.DeleteGuildError, err.Error()))
			return
		}
		res.Message = "操作成功"
		ctx.Payload(res)
	}
}
