import { request } from 'umi';
import { api } from '../api'
export interface FansTag {
    mpId?: string | number,
    beginDate?: string,
    endDate?: string,
    name?: string,
    params?: any,
    pageNum?: number,
    pageSize?: number,
    tagId?: number | string
    /**0:并集,1:交集,2:取反, */
    tagType?: 0 | 1 | 2,
}
export interface Fans {
    mpId?: string | number,
    tagId?: number | string,
    tagIds?: number | string,
    fansId?: number | string,
    fansIds?: number | string,
    nickname?: string,
    openId?: string,
    pageNum?: number,
    pageSize?: number,
    sex?: number
    subscribe?: boolean
}

/**新增粉丝标签 */
export async function addFansTag(params: FansTag) {
    let { mpId, ...param } = params
    return request(`${api}/system/mp/fans/tag/add/${mpId}`, {
        method: 'POST',
        data: param
    });
}
/**粉丝标签列表 */
export async function getFansTagList(params: { mpId: string }) {
    return request(`${api}/system/mp/fans/tag/all/${params.mpId}`);
}
/**删除标签*/
export async function delFansTag(params: { tagId: string }) {
    return request(`${api}/system/mp/fans/tag/del/${params.tagId}`, {
        method: 'DELETE',
    });
}
/**分页查询粉丝标签 */
export async function selectFansTagList(params: FansTag) {
    let { mpId, ...param } = params
    return request(`${api}/system/mp/fans/tag/list/${mpId}`, {
        method: 'POST',
        data: param,
    });
}
/**同步标签*/
export async function syncAllTag(mpId: number) {
    return request(`${api}/system/mp/fans/tag/syncAll/${mpId}`, {
        method: 'PUT'
    });
}
/**同步书城信息*/
export async function syncAllBooksApi({ mpId, platformId }: { mpId: number, platformId: number }) {
    return request(`${api}/system/mp/fans/syncPlatformFansInfo/${mpId}/${platformId}`, {
        method: 'PUT'
    });
}
/**修改标签*/
export async function editFansTag(params: FansTag) {
    let { tagId, ...param } = params
    return request(`${api}/system/mp/fans/tag/modify/${tagId}`, {
        method: 'PUT',
        data: param,
    });
}



/**粉丝列表*/
export async function getFansList(params: any) {
    let { mpId, ...param } = params
    if (param?.tagIds && !Array.isArray(param?.tagIds)) {
        param['tagIds'] = [param?.tagIds]
    }
    return request(`${api}/system/mp/fans/list/${mpId}`, {
        method: 'PUT',
        data: param,
    });
}
/** 粉丝统计信息 */
export async function getFansStatOnlineApi(mpId: number) {
    return request(`${api}/system/mp/fans/fansStatOnline/${mpId}`);
}
/** 获取粉丝订单数据 */
export async function getFansOrderListApi(props: { queryDate: string, platformId: number, mpId: string, openId: string, pageNum: number, pageSize: number, orderStatus?: 0 | 1 | 2 | -1 }) {
    return request(`${api}/platform/platformOrder/queryOrder`, { method: 'POST', data: props });
}
/**粉丝详情*/
export async function getFansDetail(params: { fansId: string }) {
    return request(`${api}/system/mp/fans/detail/${params.fansId}`);
}
/**给粉丝打标签*/
export async function putFansTag(params: Fans) {
    return request(`${api}/system/mp/fans/fansTag`, {
        method: 'PUT',
        data: params
    });
}
/**粉丝name搜索*/
export async function fansSearch(params: { nickname: string, mpId: number }) {
    let { mpId, ...param } = params
    return request(`${api}/system/mp/fans/search/${mpId}`, {
        method: 'GET',
        params: param
    });
}

/**给粉丝设置备注*/
export async function setFansRemark(params: any) {
    let { fansId, mpId, ...param } = params
    return request(`${api}/system/mp/fans/remark/${mpId}/${fansId}`, {
        method: 'POST',
        data: param,
    });
}
/**重新同步指定粉丝的信息*/
export async function putFansSync(params: { fansId: string }) {
    return request(`${api}/system/mp/fans/sync/${params.fansId}`, {
        method: 'PUT',
    });
}
/**重新同步公众号所有粉丝信息*/
export async function putFansSyncAll(params: { mpId: string }) {
    return request(`${api}/system/mp/fans/syncAll/${params.mpId}`, {
        method: 'PUT',
    });
}
/**条件查找粉丝活跃人数 */
export async function catFansNum(params: any) {
    return request(`${api}/system/mp/fans/sendCount`, {
        method: 'POST',
        data: params
    })
}
/**是否绑定广告账户*/
export async function isBoundAdAccount(mpId: any) {
    return request(`${api}/system/mp/isBoundAdAccount/${mpId}`)
}
/**创建人群包*/
export async function createAdUserPackage(params:any) {
    let {mpId,...param} = params
    return request(`${api}/system/mp/fans/createAdUserPackage/${mpId}`, {
        method: 'POST',
        data: param
    })
}