import request from "@/utils/request";
const { api, imgApi, weApi } = process.env.CONFIG;



/**获取企微列表*/
export async function api_corpUser_allOfUser(userId: string) {
    return request({ url: `/corpUser/allOfUser/${userId}` })
}
/** 获取组员及组员账号列表 */
export async function getAdAccountAllOfMember() {
    return request({ url: api + '/erp/user/subUserWithSelf' })
}

/**创建通用分组*/
export async function api_post_common_group_create(data: any) {
    return request({
        url: '/corp/common/group/create',
        method: 'POST',
        data
    })
}
/**删除通用分组*/
export async function api_post_common_group_delete(data: any) {
    return request({
        url: '/corp/common/group/delete',
        method: 'DELETE',
        params: data
    })
}
/**查询通用分组*/
export async function api_get_common_group_list(data: any) {
    return request({
        url: '/corp/common/group/list',
        method: 'GET',
        params: data
    })
}
/**通用分组枚举*/
export async function api_get_common_group_type_enym(data: any) {
    return request({
        url: '/corp/common/group/type/enum',
        method: 'GET',
    })
}
/**更新通用分组*/
export async function api_patch_common_group_update(data: any) {
    return request({
        url: '/corp/common/group/update',
        method: 'PATCH',
        params: data
    })
}
/**获取企业下的标签列表全部*/
export async function api_get_external_tag_group_list(params: { corpId: string }) {
    return request({
        url: '/corp/external/tag/group/list',
        method: 'GET',
        params
    })
}

/**
 * 获取企业下的标签组列表
 * @param data 
 * @returns 
 */
export async function getTagGroupListApi(data: any) {
    return request({
        url: '/corp/external/tag/group/list',
        method: 'POST',
        data
    });
}

export interface ApiParamsChatListProps {
    pageNum: number,
    pageSize: number,
    corpId?: string,//企业ID
    corpUserId?: string[],//企微客服id
    chatName?: string,//群名称
    createTimeEnd?: string,//群创建结束时间
    createTimeStart?: string,//群创建开始时间
    managerName?: string,//群管理名称
    ownerName?: string,//群主名称
    userCountMax?: string | number,//群人数最大值
    userCountMin?: string | number,//群人数最小值
    chatIdList?: number[],
    remark?: string
    mpAccountIdIsNull?: boolean,
    mpAccountId?: number,
    newCorpGroupChat?: boolean
}

/**
 * 企业微信群列表
 * @param data 
 * @returns 
 */
export async function getGroupChatListApi(data: ApiParamsChatListProps) {
    return request({
        url: '/corp/group/chat/list',
        method: 'POST',
        data
    })
}

/**
 * 总计
 * @param data 
 * @returns 
 */
export async function getGroupChatCountApi(data: ApiParamsChatListProps) {
    return request({
        url: '/corp/group/chat/list/count',
        method: 'POST',
        data
    })
}

/**企业微信群成员列表*/
export async function getGroupChatUserListApi(data: ApiParamsChatListProps) {
    return request({
        url: '/corp/group/chat/user/list',
        method: 'POST',
        data
    })
}

/**
 * 设置备注
 * @param data 
 * @returns 
 */
export async function setRemarkApi(data: ApiParamsChatListProps) {
    return request({
        url: '/corp/group/chat/remark',
        method: 'POST',
        data,
    })
}

/**
 * 指派公众号
 * @param data 
 * @returns 
 */
export async function setQLMpApi(data: { chatIds: string[], corpId: string, mpAccountId: number }) {
    return request({
        url: '/corp/group/chat/configCorpGroupChats',
        method: 'PUT',
        data,
    })
}

/**
 * 获取群聊变更记录
 * @param param0 
 * @returns 
 */
export async function getMpChangeRecordListApi({ corpId, chatId }: { corpId: string, chatId: string }) {
    return request({
        url: `/corp/group/chat/getMpChangeRecord/${corpId}/${chatId}`,
        method: 'GET'
    })
}

/**
 * 解散群聊
 * @param data 
 * @returns 
 */
export async function disbandChatApi(data: { corpId: string, chatIdList: string[] }) {
    return request({
        url: '/corp/group/chat/disband',
        method: 'POST',
        data
    })
}


export interface getDisbandChatLogListProps {
    pageNum: number,
    pageSize: number,
    corpId: string,
    chatName?: string
    sysUserId?: number
}
/**
 * 解散群聊日志列表
 * @param data 
 * @returns 
 */
export async function getDisbandChatLogListApi(data: getDisbandChatLogListProps) {
    return request({
        url: '/corp/group/chat/disband/list',
        method: 'POST',
        data
    })
}

/**获取背景图ID列表*/
export async function api_get_img_typeList() {
    return request({
        url: imgApi + '/img/typeList',
        method: 'GET',
    })
}
/**获取背景图对应列表*/
export async function api_post_img_list(data: {
    id: string,
    page: string,
    pageSize: string
}) {
    return request({
        url: imgApi + '/img/list',
        method: 'POST',
        data
    })
}

/**
 * 获取Appid列表
 * @param data 
 * @returns 
 */
export async function getAppIdListApi(data: { pageNum: number, pageSize: number, appId: string }) {
    return request({
        url: '/sys/app/listOfPage',
        method: 'POST',
        data
    })
}
/**游戏列表*/
export async function api_get_gameList() {
    return request({
        url: weApi + '/gameRole/gameList',
        method: 'GET',
    })
}
/**游戏列表*/
export async function api_get_gameServerList(gameId: string | number) {
    return request({
        url: weApi + `/gameRole/serverList/${gameId}`,
        method: 'GET',
    })
}


/** 获取书城列表 */
export async function getBookPlatInfoAllApi() {
    return request({
        url: api + '/erp/bookPlatform/all',
        method: 'GET'
    })
}

/** 获取所有书 */
export async function getAllBookApi() {
    return request({
        url: api + '/erp/book/all',
        method: 'GET'
    })
}

// 所有游戏列表
export async function getGameListNewApi(data: { sourceSystem: string }) {
    return request({
        url: api + `/gameData/choice/game/list`,
        method: 'POST',
        data
    });
}


// 根据书城获取书籍
export async function getBookListApi(data: { pageNum: number, pageSize: number, platformKey: string, bookName?: string }) {
    return request({
        url: `/corp/externalUser/platform/bookList`,
        method: 'POST',
        data
    });
}

// 根据书城书籍获取章节
export async function getBookChapterListListApi(data: { pageNum: number, pageSize: number, platformKey: string, bookName: string, chapterName?: string }) {
    return request({
        url: `/corp/externalUser/platform/chapterList`,
        method: 'POST',
        data
    });
}

// 小程序链接
export async function getGenerateUrllinkApi(data: { path: string, query: string, appId: string }) {
    const { appId, ...d } = data
    return request({
        url: api + `/miniapp/api/miniappBase/generateUrllink/${appId}`,
        method: 'POST',
        data: d
    });
}

/**
 * 获取所有企微客服号
 * @param params 
 * @returns 
 */
export async function getCorpUserListApi(params: { userId?: number }) {
    return request({
        url: api + '/corpOperation/landing/get/corp/user',
        method: 'GET',
        params
    });
}