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

/**
 * 新增任务
 * @param data 
 * @returns 
 */
export async function addTaskApi(data: BUSINES_SPLAN_API.AddTaskProps) {
    return request({
        url: api + `/corpOperation/corp/create/project/task/add`,
        method: 'POST',
        data
    });
}

/**
 * 修改
 * @param data 
 * @returns 
 */
export async function updateTaskApi({ projectId, ...data }: BUSINES_SPLAN_API.AddTaskProps) {
    return request({
        url: api + `/corpOperation/corp/create/project/task/edit/${projectId}`,
        method: 'POST',
        data
    });
}

/**
 * 计划列表
 * @param data 
 * @returns 
 */
export async function getProjectListApi(data: BUSINES_SPLAN_API.GetProjectListProps) {
    return request({
        url: api + `/corpOperation/corp/create/project/listOfPage`,
        method: 'POST',
        data
    });
}

/**
 * 获取计划任务详情
 * @param projectId 
 * @returns 
 */
export async function getProjectDetailsApi(projectId: string) {
    return request({
        url: api + `/corpOperation/corp/create/project/getDetail/${projectId}`,
        method: 'GET',
    });
}

/**
 * 计划添加至项目组
 * @param param0 
 * @returns 
 */
export async function addProjectToGroupApi({ groupId, projectIds }: { groupId: number, projectIds: number[] }) {
    return request({
        url: api + `/corpOperation/corp/create/project/addProjectToGroup/${groupId}`,
        method: 'POST',
        data: projectIds
    });
}

/**
 * 获取计划详情
 * @param projectId 
 * @returns 
 */
export async function getCreateDetailsApi(projectId: string) {
    return request({
        url: api + `/corpOperation/corp/create/project/selectById/${projectId}`,
        method: 'POST',
    });
}


/**
 * 删除计划
 * @param params 
 * @returns 
 */
export async function delProjectApi(data: { projectIds: number[] }) {
    return request({
        url: api + `/corpOperation/corp/create/project/batchDelByIds`,
        method: 'POST',
        data: data.projectIds
    });
}

/**
 * 停止计划
 * @param data 
 * @returns 
 */
export async function cancelProjectApi(data: { projectIds: number[], pause: boolean }) {
    return request({
        url: api + `/corpOperation/corp/create/project/cancel/${data.pause}`,
        method: 'POST',
        data: data.projectIds
    });
}

/**
 * 任务日志
 * @param projectId 
 * @returns 
 */
export async function getProjectLogListApi(projectId: number) {
    return request({
        url: api + `/corpOperation/corp/create/project/getDetail/${projectId}`,
        method: 'GET'
    });
}


interface ListProps {
    pageNum: number,
    pageSize: number,
}
export interface WelcomeMsgCorpUserList extends ListProps {
    welcomeMsgId?: any,//欢迎语Id
}

/**获取送达客户列表*/
export async function api_post_welcomeMsg_corpExternalUserList(data: WelcomeMsgCorpUserList) {
    return request({
        url: `/corp/welcomeMsg/corpExternalUserList`,
        method: 'POST',
        data
    });
}

/**获取欢迎语应用的企微号列表*/
export async function api_post_welcomeMsg_welcomeMsgCorpUserList(data: WelcomeMsgCorpUserList) {
    return request({
        url: `/corp/welcomeMsg/welcomeMsgCorpUserList`,
        method: 'POST',
        data
    });
}


export interface GetSendTaskGroupuserListProps {
    pageNum: number,
    pageSize: number,
    corpId?: string,
    msgId?: string,
    sendTimeEndTime?: string
    sendTimeStartTime?: string
    status?: number
    taskId: number,
    userId?: string,
    createStartDate?: string,
    createEndDate?: string
}
/**
 * 群发获取下发企微号列表
 * @param data 
 * @returns 
 */
export async function getSendTaskGroupuserListApi(data: GetSendTaskGroupuserListProps) {
    return request({
        url: `/corp/group/send/task/user/list`,
        method: 'POST',
        data
    });
}

/**
 * 下载下发企微号列表
 * @param data 
 * @returns 
 */
export async function downloadSendTaskuserApi(data: GetSendTaskGroupuserListProps) {
    return request({
        url: `/corp/group/send/task/user/excel`,
        method: 'POST',
        data,
        responseType: 'blob'
    });
}

/**
 * 群群发获取下发企微号列表
 * @param data 
 * @returns 
 */
export async function getSendGroupTaskGroupuserListApi(data: GetSendTaskGroupuserListProps) {
    return request({
        url: api + `/corpOperation/corp/group/send/task/user/list`,
        method: 'POST',
        data
    });
}

/**
 * 获取高级群发下发企微号列表
 * @param data 
 * @returns 
 */
export async function getMessageSendTaskuserListApi(data: GetSendTaskGroupuserListProps) {
    return request({
        url: `/corp/message/send/task/user/list`,
        method: 'POST',
        data
    });
}

/**
 * 高级群发消息重试
 * @returns 
 */
export async function putMessageUpdateApi(id: any) {
    return request({
        url: `/corp/message/send/taskLog/status/update/${id}`,
        method: 'PUT',
    });
}


/**
 * 群发取消发送
 * @param params 
 * @returns 
 */
export async function cancelGroupSendApi(params: { corpId: string, msgId: string }) {
    return request({
        url: `/corp/group/send/task/msg/cancel`,
        method: 'PATCH',
        params
    });
}

/**
 * 群发提醒发送
 * @param params 
 * @returns 
 */
export async function remindGroupSendApi(params: { corpId: string, msgId: string }) {
    return request({
        url: `/corp/group/send/task/msg/remind`,
        method: 'PATCH',
        params
    });
}


/**
 * 群发送达客户列表同步
 * @param params 
 * @returns 
 */
export async function syncSendGroupTaskExternalApi(params: { id: number, taskId: string }) {
    return request({
        url: `/corp/group/send/task/external/user/sync`,
        method: 'PATCH',
        params
    });
}

/**
 * 群发下发企微号列表同步
 * @param params 
 * @returns 
 */
export async function syncSendGroupTaskUserApi(params: { corpId: string, taskId: string }) {
    return request({
        url: `/corp/group/send/task/user/sync`,
        method: 'PATCH',
        params
    });
}



export async function getGroupFailUserListApi(params: { corpId: string, msgId: string, taskId: string }) {
    return request({
        url: `/corp/group/send/task/msg/fail/external/user/list`,
        method: 'GET',
        params
    });
}


/**
 * 群发重新发送
 * @param data 
 * @returns 
 */
export async function reSendGroupTaskApi(data: { id: number, corpUserId?: string }) {
    return request({
        url: `/corp/group/send/task/reSend`,
        method: 'POST',
        data
    });
}

export interface GetSendTaskGroupMsgListProps {
    corpId?: string,
    pageNum: number,
    pageSize: number,
    taskId: number,
    sendTimeEndTime?: string
    sendTimeStartTime?: string
}
/**
 * 获取群发记录列表
 * @param data 
 * @returns 
 */
export async function getSendTaskGroupMsgListApi(data: GetSendTaskGroupMsgListProps) {
    return request({
        url: `/corp/group/send/task/msg/list`,
        method: 'POST',
        data
    });
}

/**
 * 获取群群发记录列表
 * @param data 
 * @returns 
 */
export async function getSendGroupTaskGroupMsgListApi(data: GetSendTaskGroupMsgListProps) {
    return request({
        url: api + `/corpOperation/corp/group/send/task/msg/list`,
        method: 'POST',
        data
    });
}

/**
 * 转发记录
 * @param data 
 * @returns 
 */
export async function getSendGroupTaskRobotListApi(data: GetSendTaskGroupuserListProps) {
    return request({
        url: api + `/corpOperation/corp/group/send/task/robot/list`,
        method: 'POST',
        data
    });
}

/**
 * 转发消息重试
 * @returns 
 */
export async function putMessageUpdateReloadApi(taskLogId: any) {
    return request({
        url: `/corp/group/send/taskLog/status/update/${taskLogId}`,
        method: 'PUT',
    });
}

/**
 * 获取高级群发记录列表
 * @param data 
 * @returns 
 */
export async function getMessageSendTaskMsgListApi(data: GetSendTaskGroupMsgListProps) {
    return request({
        url: `/corp/message/send/task/msg/list`,
        method: 'POST',
        data
    });
}

/**
 * 继承日志
 * @param data 
 * @returns 
 */
export async function inheritLogList(data: any) {
    return request({
        url: api + `/corpOperation/corpExternalUserTransferTasks/logListOfPage`,
        method: 'POST',
        data
    });
}

/**日志统计*/
export async function inheritLogCount(data: any) {
    return request({
        url: api + `/corpOperation/corpExternalUserTransferTasks/count`,
        method: 'POST',
        data
    });
}

/**
 * 朋友圈下发企微号
 * @param data 
 * @returns 
 */
export async function getMomentCorpUserListApi(data: any) {
    return request({
        url: `/corp/moment/corpUserList`,
        method: 'POST',
        data
    })
}


export async function getSendLogApi(data: any) {
    return request({
        url: `/corp/moment/jobList`,
        method: 'POST',
        data
    })
}



/**
 * 朋友圈下发企微号列表
 * @param data 
 * @returns 
 */
export async function getMomentsCorpUserListApi(data: { pageNum: number, pageSize: number, corpMomentId: number }) {
    return request({
        url: `/corp/moment/corpUserList`,
        method: 'POST',
        data
    })
}


/**
 * 朋友圈发送记录
 * @param data 
 * @returns 
 */
export async function getMomentsSendLogApi(data: { pageNum: number, pageSize: number, corpMomentId: number }) {
    return request({
        url: `/corp/moment/jobList`,
        method: 'POST',
        data
    })
}