import request from '@/utils/request'


/**
 * 企微去授权
 * @param {*} params {redirectUri: 回调地址}
 * @returns 
 */
export function getCorpToAuth(params) {
    return request({
        url: '/corp/admin/corp/toAuth',
        method: 'get',
        params
    })
}


/**
 * 授权成功回调
 * @param {*} data {authCode: 回调的 code，expiresIn："临时授权码有效时常", state: 回调的 state} 
 * @returns 
 */
export function addCorpDoAuth(data) {
    return request({
        url: '/corp/admin/corp/doAuth',
        method: 'POST',
        data
    })
}


/**
 * 获取企微列表
 * @param {*} data {pageSize: 20, pageNum: 1, corpName: "企微名", corpId: "企微 id"}
 * @returns 
 */
export function getCorpList(data) {
    return request({
        url: '/corp/admin/corp/list',
        method: 'POST',
        data
    })
}

/**
 * 刷新企微信息
 * @param {*} corpId 
 * @returns 
 */
export function putRefreshCorp(corpId) {
    return request({
        url: `/corp/admin/corp/refresh/${corpId}`,
        method: 'PUT'
    })
}

/**
 * 获取企微通讯录
 * @param {*} data {pageNum: 1, pageSize: 20, corpId: "企微 id(必传)", name: ""}
 * @returns 
 */
export function getCorpMailList(data) {
    return request({
        url: `/corp/admin/corpUser/list`,
        method: 'POST',
        data
    })
}

/**
 * 指派投手运营
 * @param {*} data  {corpId: "", corpUserId: "", beginTime: "2023-01-01", putUserId: 1, operUserId: 2}
 * @returns 
 */
export function putCorpSysUser(data) {
    return request({
        url: `/corp/admin/corpUser/configSysUser`,
        method: 'PUT',
        data
    })
}

/**
 * 同步企微通讯录
 * @param {*} corpId 
 * @returns 
 */
export function putSyncCorpUser(corpId) {
    return request({
        url: `/corp/admin/corpUser/sync/${corpId}`,
        method: 'PUT'
    })
}

/**
 * 同步所有
 * @param {*} corpId 
 * @returns 
 */
export function putSyncAllCorpUser(corpId) {
    return request({
        url: `/corp/admin/corp/syncAll/${corpId} `,
        method: 'PUT'
    })
}


/**
 * 更新企微明文密钥
 * @param {*} corpId 
 * @param {*} data {"originCorpId":"企微 id", userSecret:"通讯录密钥",externalUserSecret:"客户密钥", remark:"备注" }
 * @returns 
 */
export function refreshCorp(params) {
    const { corpId, ...data } = params
    return request({
        url: `/corp/admin/corp/config/${corpId}`,
        method: 'PUT',
        data
    })
}

/**
 * 设置会话存档Secret
 * @param {*} corpId 
 * @param {*} msgAuditSecret 
 * @returns 
 */
export function setMsgSession(params) {
    const { corpId, msgAuditSecret } = params
    return request({
        url: `/corp/admin/corp/config/${corpId}/${msgAuditSecret}`,
        method: 'POST'
    })
}

/*****************变更记录*******************/
/**
 * 变更记录
 * @param {*} corpId 
 * @param {*} corpUserId 
 * @returns 
 */
export function getAllOfCorpList(corpId, corpUserId) {
    return request({
        url: `/corp/admin/corpUserChangeRecord/allOfCorp/${corpId}/${corpUserId}`,
        method: 'GET'
    })
}

/**
 * 新增记录
 * @param {*} data {nextId: 1, corpId: "", corpUserId:"", beginTime: "2021-01-01", putUserId: 1, operUserId: 1}
 * @returns 
 */
export function addAllOfCorp(data) {
    return request({
        url: `/corp/admin/corpUserChangeRecord/addNewRecord`,
        method: 'POST',
        data
    })
}

/**
 * 修改记录
 * @param {*} data {recordId: 1, beginTime: "2021-01-01", putUserId: 1, operUserId: 1}
 * @returns 
 */
export function putAllOfCorp(data) {
    return request({
        url: `/corp/admin/corpUserChangeRecord/modifyRecord`,
        method: 'PUT',
        data
    })
}

/**
 * 删除记录
 * @param {*} recordId 
 * @returns 
 */
export function delAllOfCorp(recordId) {
    return request({
        url: `/corp/admin/corpUserChangeRecord/delRecord/${recordId}`,
        method: 'DELETE',
    })
}

/*****************变更记录*******************/


/**
 * 新增企业
 * @param {*} data 
 * @returns 
 */
export function addCorpApi(data) {
    return request({
        url: '/corp/admin/corp/add',
        method: 'POST',
        data
    })
}

/**
 * 修改企业
 * @param {*} data 
 * @returns 
 */
export function editCorpApi(data) {
    return request({
        url: '/corp/admin/corp/modify',
        method: 'POST',
        data
    })
}


/**
 * 服务商列表
 * @returns 
 */
export function getProviderList() {
    return request({
        url: '/corp/admin/corp/provider/list',
        method: 'GET'
    })
}


/**
 * 服务商应用授权二维码
 * @param {*} params 
 * @returns 
 */
export function getProviderAuth(params) {
    return request({
        url: '/corp/admin/corp/getProviderAuth',
        method: 'GET',
        params
    })
}


/**
 * 上传图片
 * @param {filePrefix: corp_info/corp_icp/, suffix: jpg/png} params 
 * @returns 
 */
export function uploadImageApi(params) {
    return request({
        url: '/corp/corp/media/formUpload',
        method: 'GET',
        params
    })
}