package eta_forum

import (
	"encoding/json"
	"fmt"
)

type GetForumAdminAuthCodeResp struct {
	Ret         int
	Msg         string
	ErrMsg      string
	ErrCode     string
	Data        *LoginAuthCode
	Success     bool `description:"true 执行成功，false 执行失败"`
	IsSendEmail bool `json:"-" description:"true 发送邮件，false 不发送邮件"`
	IsAddLog    bool `json:"-" description:"true 新增操作日志，false 不新增操作日志" `
}
type LoginAuthCode struct {
	AuthCode string `json:"auth_code" description:"登录凭证"`
}

// GetLoginAuthCodeReq 获取登录编码请求体
type GetLoginAuthCodeReq struct {
	AdminName string `description:"用户名"`
	Source    int    `description:"来源: 1-CRM; 2-ETA"`
}

// GetForumAdminAuthCode 获取登录凭证
func GetForumAdminAuthCode(adminName string) (authCode string, err error) {
	// 查询图表信息
	param := GetLoginAuthCodeReq{
		Source:    1,
		AdminName: adminName,
	}
	reqJson, e := json.Marshal(param)
	if e != nil {
		err = fmt.Errorf("data json marshal err: %s", e.Error())
		return
	}
	respItem, err := GetForumAdminAuthCodeLib(string(reqJson))
	if err != nil {
		err = fmt.Errorf("获取登录凭证,Err:" + err.Error())
		return
	}
	if respItem.Ret != 200 {
		err = fmt.Errorf("获取登录凭证,Err:" + respItem.ErrMsg)
		return
	}

	if respItem.Data != nil {
		authCode = respItem.Data.AuthCode
	}
	return
}
