import { queryStr } from "@/utils/query";
import { request } from "umi";
import { api } from '../api'
export interface Params {
    eventType?: number,
    medias?: {
        mediaId?: number,
        msgType?: string,
        textContent?: string,
        type?: number,
        wxMediaId?: string
    }[],
    mpId?: number,
    msgStrategy?: number,
    resDelayTime?: number,
    strategyDesc?: string,
    textKey?: string,
    strategyId?: string
}
/**新建策略 */
export async function addMsgResStrategy(params: Params) {
    let { mpId, ...param } = params
    return request(`${api}/system/mp/replyStrategy/delay/${mpId}`, {
        method: 'POST',
        data: param
    });
}
/**策略详情 */
export async function getMsgResStrategy(params: { strategyId: string }) {
    return request(`${api}/system/mp/msgResStrategy/detail/${params.strategyId}`);
}
/**删除策略*/
export async function delMsgResStrategy(params: { strategyId: string }) {
    return request(`${api}/system/mp/replyStrategy/del/${params.strategyId}`, {
        method: 'DELETE',
    });
}

/**编辑策略*/
export async function editMsgResStrategy(params: Params) {
    let { mpId, strategyId, ...param } = params
    console.log('mpId===>',mpId,params)
    return request(`${api}/system/mp/replyStrategy/delay/${mpId}/${strategyId}`, {
        method: 'PUT',
        data: param,
    });
}

/**新建或者编辑立即回复策略*/
export async function editMsgResStrategyIm(params: Params) {
    let { mpId, ...param } = params
    return request(`${api}/system/mp/replyStrategy/immediately/${mpId}`, {
        method: 'PUT',
        data: param,
    });
}
/**查询指定公众号的消息回复策略 */
export async function searchMsgResStrategy(params: { mpId: string, eventType?: number, strategyDesc?: string }) {
    let { mpId, ...param } = params
    return request(`${api}/system/mp/replyStrategy/delay/search/${mpId}`, {
        method: 'POST',
        data: param
    });
}
/** 开关策略*/
export async function editEnabled(params: { strategyId: number, enabled: boolean }) {
    let { strategyId, enabled } = params
    return request(`${api}/system/mp/replyStrategy/enabled/${strategyId}/${enabled}`, {
        method: 'PUT',
    });
}

/**查询指定公众号立即回复的消息回复策略 */
export async function searchImMsgResStrategy(params: { mpId: string, eventType?: number, textKey?: string }) {
    let { mpId, ...param } = params
    return request(`${api}/system/mp/replyStrategy/immediately/${mpId}${queryStr(param)}`);
}

/**回复策略获取详情 */
export async function searchDetails(params: { strategyId: string }) {
    let { strategyId } = params
    return request(`${api}/system/mp/replyStrategy/${strategyId}`);
}

/**回复策略获取详情 */
export async function getMpClickMenuList(params: { mpId: string }) {
    let { mpId } = params
    return request(`${api}/system/mp/replyStrategy/mpClickMenuList/${mpId}`);
}
/**延迟消息预览 */
export async function replyStrategyPreview(params: { fansIds?: string, mpIds: any[] }) {
    let { fansIds, ...param } = params
    return request(`${api}/system/mp/replyStrategy/preview/${param?.mpIds[0]}/${fansIds}`, {
        method: 'POST',
        data: param
    });
}


/**延迟消息导入Excel*/
export async function importPushExcle(props: { data: FormDataEntryValue }) {
    return request(`${api}/system/mp/replyStrategy/import`, {
        method: 'POST',
        body: props.data
    })
}

