package controllers

import (
	"eta/eta_mobile/models"
	"eta/eta_mobile/services"
	"eta/eta_mobile/utils"
)

type VarietyTagController struct {
	BaseAuthController
}

// TagTree
// @Title 标签树
// @Description 标签树
// @Success 200 string "获取成功"
// @router /variety_tag/tag_tree [get]
func (this *VarietyTagController) TagTree() {
	br := new(models.BaseResponse).Init()
	br.IsSendEmail = false
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	// 非自用不请求
	resp := make([]*services.TagTreeItem, 0)
	if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
		br.Ret = 200
		br.Success = true
		br.Msg = "获取成功"
		br.Data = resp
		return
	}

	hasResearcher, _ := this.GetInt("HasResearcher")    // 是否展示研究员：1展示， 0不展示
	include, _ := this.GetInt("IncludeDisableMember")   // 是否包含被禁用的研究员标签
	questionId, _ := this.GetInt("CommunityQuestionId") // 问答社区ID-用于区分哪些研究员不可选
	list, e := services.GetTagTree(hasResearcher, include, questionId)
	if e != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "TagTree-获取标签树失败, Err: " + e.Error()
		return
	}
	resp = list

	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}
