package enterprise_wechat

import (
	"fmt"
	"git.rosy.net.cn/baseapi/utils"
	"net/http"

	"errors"
)

// GetDepartmentList 获取部门id列表
func (a *API) GetDepartmentList() {
	a.CheckAccessTokenExpiresIn()
	param := map[string]interface{}{"access_token": a.accessToken}
	departmentList, err := a.AccessAPI(WeChatBaseApi, GetDepartmentList, http.MethodGet, param)
	fmt.Println(departmentList)
	fmt.Println(err)
}

// GetEnterpriseStaffInfo 获取企业部门用户详细情况
func (a *API) GetEnterpriseStaffInfo(department int) ([]*UserList, error) {
	a.CheckAccessTokenExpiresIn()
	departmentUserDetail, err := a.AccessAPI(WeChatBaseApi, GetDepartmentUserDetail, http.MethodGet, map[string]interface{}{"fetch_child": 1, "department_id": department, "access_token": a.accessToken})
	if err != nil {
		return nil, err
	}
	result := &GetEnterpriseStaffInfoRes{}
	if err := utils.Map2StructByJson(departmentUserDetail, result, false); err != nil {
		return nil, err
	}

	if result.ErrCode != 0 {
		return nil, errors.New(result.ErrMsg)
	}

	return result.UserList, nil
}
