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

export interface getCorpUserChatListProps {
    pageNum: number,
    pageSize: number,
    putUserId?: number,
    operUserId?: number,
    corpUserName?: string,
    corpIds?: string[],
    corpUserIds?: string[],
    status?: number
}

/**
 * 群主号列表
 * @param data 
 * @returns 
 */
export function getCorpUserChatListApi(data: getCorpUserChatListProps) {
    return request({
        url: api + `/corpOperation/corpUserChat/list`,
        method: 'POST',
        data
    })
}

/**
 * 删除群主号
 * @param data 
 * @returns 
 */
export function delCorpUserChatApi(data: number[]) {
    return request({
        url: api + `/corpOperation/corpUserChat/deleteBatch`,
        method: 'DELETE',
        data
    })
}


interface AddCorpUserChatProps {
    corpUserList: {
        corpId: string,
        corpUserId: string
    }[]
}

/**
 * 新增群主号
 * @param data 
 * @returns 
 */
export function addCorpUserChatApi(data: AddCorpUserChatProps) {
    return request({
        url: api + `/corpOperation/corpUserChat/add`,
        method: 'POST',
        data
    })
}


/**
 * 查询群主号绑定的客户号或者机器人号详情
 * @param param0 
 * @returns 
 */
export function getBindDetailListApi({ corpUserChatId, bindType }: { corpUserChatId: number, bindType: number }) {
    return request({
        url: api + `/corpOperation/corpUserChat/corpUserChatRelation/listBindDetail/${corpUserChatId}/${bindType}`,
        method: 'GET'
    })
}

interface BindCorpUserChatProps {
    bindType: 1 | 2,
    corpUserChatId: number,
    corpUserList: {
        corpId: string,
        corpUserId: string
        transferExternalUserId: string
    }[]
}

/**
 * 绑定客户号或者机器人号
 * @param data 
 * @returns 
 */
export function bindCorpUserChatApi(data: BindCorpUserChatProps) {
    return request({
        url: api + `/corpOperation/corpUserChat/bind`,
        method: 'POST',
        data
    })
}

/**
 * 解绑客户号或者机器人号
 * @param data 
 * @returns 
 */
export function unbindCorpUserChatApi(data: BindCorpUserChatProps) {
    return request({
        url: api + `/corpOperation/corpUserChat/unbind`,
        method: 'POST',
        data
    })
}

/**
 * 同步当前群主号下的所有群聊的机器人
 * @param data 
 * @returns 
 */
export function syncCorpChatRobotApi(data: { corpId: string, corpUserId: string, robotIdList: string[] }) {
    return request({
        url: `/corp/group/chat/syncCorpChatRobot`,
        method: 'PUT',
        data
    })
}

/**
 * 所有群主号
 * @param params 
 * @returns 
 */
export function getCorpUserChatAllListApi(params: { corpUserName?: string }) {
    return request({
        url: api + `/corpOperation/corpUserChat/listAll`,
        method: 'POST',
        params
    })
}

/**
 * 查询群主号下客服号 机器人号
 * @param params 
 * @returns 
 */
export function getCorpUserChatCorpUserListApi(data: { bindType: 1 | 2, corpUserChatIds: number[] }) {
    return request({
        url: api + `/corpOperation/corpUserChat/corpUserChatRelation/listBindDetails`,
        method: 'POST',
        data
    })
}