import { request } from 'umi';
import { api } from '../api';


/**
 * 查询优化目标权限
 * @param data 
 * @returns 
 */
export async function getOptimizationGoalPermissionsV3Api(data: any) {
    return request(api + `/adq/v3/launch/tools/getOptimizationGoalPermissions`, {
        method: 'POST',
        data
    })
}

/**
 * 获取地理位置
 * @param data 
 * @returns 
 */
export async function getTargetingGagsApi(data: any) {
    return request(api + `/adq/v3/launch/tools/getTargetingGags`, {
        method: 'POST',
        data
    })
}


/**
 * 获取小说列表
 * @param data
 * @returns
 */
export async function getmarketingAssetContentApi(data: {
    marketingAssetType?: string,
    marketingAssetName?: string,
    accountId: number,
    pageNum: number,
    pageSize: number,
    marketingAssetNameList: string[]
}) {
    return request(api + `/adq/v3/marketingAssets/marketingAssetContent/get`, {
        method: 'POST',
        data,
    });
}

/**
 * 远程小说接口
 * @param data 
 * @returns 
 */
export async function getByRemotemarketingAssetContentApi(data: {
    marketingAssetType?: string,
    marketingAssetName?: string,
    accountId: number,
    pageNum: number,
    pageSize: number,
    marketingIdList: number[]
}) {
    return request(api + `/adq/v3/marketingAssets/marketingAssetContent/getByRemote`, {
        method: 'POST',
        data,
    });
}

/**
 * 同步小说
 * @param data
 * @returns
 */
export async function synMarketingAssetContentApi(data: { accountId: number }) {
    return request(api + `/adq/v3/marketingAssets/marketingAssetContent/sync`, {
        method: 'POST',
        data,
    });
}

/**
 * 获取公众号
 * @param data 
 * @returns 
 */
export async function getWechatOfficialAccountApi(data: { accountId: number }) {
    return request(api + `/adq/v3/marketingAssets/getWechatOfficialAccounts`, {
        method: 'POST',
        data,
    });
}

/**
 * 批量获取公众号
 * @param data 
 * @returns 
 */
export async function getWechatOfficialAccountsApi(data: { accountIdList: number[] }) {
    return request(api + `/adq/v3/marketingAssets/getWechatOfficialAccountsBatch`, {
        method: 'POST',
        data,
    });
}

/**
 * 获取视频号
 * @param data 
 * @returns 
 */
export async function getVideoChannelInfoApi(data: { accountIdList?: number[], accountId?: number }) {
    return request(api + `/adq/v3/marketingAssets/getVideoChannelInfo`, {
        method: 'POST',
        data,
    });
}

/**
 * 批量获取视频号
 * @param data 
 * @returns 
 */
export async function getVideoChannelInfoBatchApi(data: { accountIdList?: number[], accountId?: number }) {
    return request(api + `/adq/v3/marketingAssets/getVideoChannelInfoBatch`, {
        method: 'POST',
        data,
    });
}

/**
 * 获取转化归因
 * @param data 
 * @returns 
 */
export async function getConversionInfoApi(data: {
    accountId: number,
    pageNum: number,
    pageSize: number,
    accessStatus?: string[] // ACCESS_STATUS_COMPLETED 已接入 ACCESS_STATUS_PENDING 待接入
    conversionId?: number,
    conversionName?: string,
    conversionType?: string, // 扣费类型(ID_TYPE_CPC, BID_TYPE_CPA, BID_TYPE_CPS, BID_TYPE_CPM, BID_TYPE_CPD)
    createSourceType?: string,  // 转化创建来源，如 （SELF_CREATED 自建转化),(PLATFORM 平台类转化)
    deepBehaviorOptimizationGoal?: string,
    deepWorthAdvancedGoal?: string,
    deepWorthOptimizationGoal?: string,
    marketingScene?: string,
    optimizationGoal?: string,
    siteSet?: string,
}) {
    return request(api + `/adq/v3/launch/tools/getConversionInfo`, {
        method: 'POST',
        data,
    });
}


/**
 * 获取数据源
 * @param data
 * @returns
 */
export async function getDataSourceV3Api(data: { accountIds: number[], promotedObjectType?: string }) {
    return request(api + `/adq/v3/userActionSets/allByAccount`, {
        method: 'POST',
        data
    })
}

/**
 * 同步数据源
 * @param data
 * @returns
 */
export async function sysDataSourceV3Api(data: number[]) {
    return request(api + `/adq/v3/userActionSets/syncByAdAccountId`, {
        method: 'PATCH',
        data,
    });
}


/**
 * 获取创意规格详情
 * @param data 
 * @returns 
 */
export async function getCreativeDetailsApi(data: any) {
    return request(api + `/adq/v3/launch/tools/getCreativeDetails`, {
        method: 'POST',
        data
    })
}


/**
 * 获取流量包
 * @param data 
 * @returns 
 */
export async function getBatchUnionPositionPackagesApi(data: { unionPackageType: 'UNION_PACKAGE_TYPE_INCLUDE' | 'UNION_PACKAGE_TYPE_EXCLUDE', accountId?: number, accountIds?: number[] }) {
    return request(api + `/adq/v3/marketingAssets/getBatchUnionPositionPackages`, {
        method: 'POST',
        data,
    });
}

/**
 * 获取人群包
 * @param params 
 * @returns 
 */
export async function getAudiencesListApi(params: { adAccountId: number, audienceId?: number }) {
    return request(api + `/adq/v3/custom/audiences/get`, {
        method: 'GET',
        params
    });
}

/**
 * 获取创意规格列表
 * @param data 
 * @returns 
 */
export async function getCreativeTemplateListApi(data: any) {
    return request(api + `/adq/v3/launch/tools/getCreativeTemplateList`, {
        method: 'POST',
        data
    })
}


/**
 * 文案助手
 * @param params 
 * @returns 
 */
export async function getTextApi(params: { maxTextLength: number, adAccountId: number }) {
    return request(api + `/adq/v3/launch/tools/creative/tools/text`, {
        method: 'GET',
        params
    })

}

/**
 * 获取原生页授权方信息
 * @param accountId 
 * @returns 
 */
export async function getWXDownPageAuthInfoListApi(accountId: number) {
    return request(api + `/adq/v3/marketingAssets/listWXDownPageAuthInfo/${accountId}`, {
        method: 'GET'
    });
}

/**
 * 获取ADQ落地页列表
 * @param adgroupName 广告名称
 * @param promotedObjectType 广告类型
 * @param accountId 账户ID
 */
export async function getAdqLandingPageListApi(params: {
    pageNum: number;
    pageSize: number;
    accountId?: number;
    pageName?: string;
    pageType?: string;
    pageTemplateId?: string;
    pageStatus?: string;
    ownerUid?: number;
    creativeTemplateId?: number,
    marketingCarrierId?: string,
    marketingCarrierType?: string
    marketingGoal?: string,
    marketingSubGoal?: string,
    marketingTargetType?: string,
    siteSet?: string[],
}) {
    Object.keys(params).forEach(key => {
        if (!params[key as keyof typeof params]) {
            delete params[key as keyof typeof params]
        }
    })
    return request(api + '/adq/v3/marketingAssets/listWXDownPageToRemote', {
        method: 'POST',
        data: params,
    });
}

/**
 * 删除落地页
 * @param data 
 * @returns 
 */
export async function delPageApi(data: { accountId: number, pageIds: number[] }) {
    return request(api + `/adq/v3/marketingAssets/batchDelWXDownPage`, {
        method: 'DELETE',
        data
    });
}

/**
 * 灵鹊落地页
 * @param params 
 * @returns 
 */
export async function getAdqLandingPageOfficialListApi(params: {
    pageNum: number;
    pageSize: number;
    accountId?: number;
    creativeTemplateId?: number,
    marketingCarrierId?: string,
    marketingCarrierType?: string
    marketingGoal?: string,
    marketingSubGoal?: string,
    marketingTargetType?: string,
    siteSet?: string[],
    ownerUid?: number,
    pageIds?: number[],
    pageName?: string,
    pageStatus?: string,
    pageType?: string,
    userId?: number
}) {
    Object.keys(params).forEach(key => {
        if (!params[key as keyof typeof params]) {
            delete params[key as keyof typeof params]
        }
    })
    return request(api + '/adq/v3/marketingAssets/listDownPageToRemote', {
        method: 'POST',
        data: params,
    });
}

/**
 * 按账号同步落地页
 * @param adAccountId 本地ID
 */
export async function putAdqLandingPageApi(data: any) {
    return request(api + `/adq/v3/marketingAssets/syncAllWXDownPage`, {
        method: 'PUT',
        data
    });
}


/**
 * 获取品牌形象列表
 * @returns 
 */
export async function getSysBrandApi() {
    return request(api + `/adq/sysBrand/allOfUser`, {
        method: 'GET'
    })
}

/**
 * 新增品牌形象
 * @param data 
 * @returns 
 */
export async function addSysBrandApi(data: { name: string, brandImgUrl: string }) {
    return request(api + `/adq/sysBrand`, {
        method: 'POST',
        data
    })
}

/**
 * 修改品牌形象
 * @param data 
 * @returns 
 */
export async function editSysBrandApi(data: { name: string, brandImgUrl: string, sysBrandId: number }) {
    const { sysBrandId, ...params } = data
    return request(api + `/adq/sysBrand/${sysBrandId}`, {
        method: 'PUT',
        data: params
    })
}

/**
 * 删除品牌形象
 * @param data 
 * @returns 
 */
export async function delSysBrandApi(data: { sysBrandId: number }) {
    const { sysBrandId } = data
    return request(api + `/adq/sysBrand/${sysBrandId}`, {
        method: 'DELETE'
    })
}


/**
 * 新增头像昵称跳转页
 * @param data 
 * @returns 
 */
export async function addProfilesApi(data: { profileName: string, imageUrl: string, description: string }) {
    return request(api + `/adq/v3/marketingAssets/profiles/add`, {
        method: 'POST',
        data
    })
}

/**
 * 获取头像昵称跳转页
 * @param data 
 * @returns 
 */
export async function getProfilesApi(data: { profileName?: string }) {
    return request(api + `/adq/v3/marketingAssets/profiles/get`, {
        method: 'POST',
        data
    })
}

/**
 * 删除头像昵称跳转页
 * @param data 
 * @returns 
 */
export async function delProfilesApi(params: { id: number }) {
    return request(api + `/adq/v3/marketingAssets/deleteSysProfiles`, {
        method: 'DELETE',
        params
    })
}

/**
 * 获取创意审核详情
 * @param data 
 * @returns 
 */
export async function getCreativeReviewDetailApi({ accountId, dynamicCreativeIds }: { accountId: number, dynamicCreativeIds: number[] }) {
    return request(api + `/adq/adgroup/creativeReviewDetail`, {
        method: 'POST',
        data: dynamicCreativeIds,
        params: { accountId }
    })
}

/**
 * 查询元素组件申诉复审结果
 * @param data 
 * @returns 
 */
export async function getFsResultApi(data: { accountId: number, componentId: number, dynamicCreativeId: number, elementFingerPrint: string, elementId: number }) {
    return request(api + `/adq/adgroup/getResult`, {
        method: 'POST',
        data
    })
}

/**
 * 同步广告
 * @param data 
 * @returns 
 */
export async function syncAdInfoApi(data: { accountAdgroupMaps: string[], adgroupCreateLogId: number }) {
    return request(api + `/adq/syncAdInfo/syncByAdgroupIds`, {
        method: 'POST',
        data
    })
}

/**
 * 获取图片信息
 * @param data 
 * @returns 
 */
export async function getImagesInfoApi(data: { adAccountId: number, imageIds: number[], pageNum: number, pageSize: number }) {
    return request(api + `/adq/v3/marketingAssets/getImages`, {
        method: 'POST',
        data
    })
}

/**
 * 获取视频信息
 * @param data 
 * @returns 
 */
export async function getVideosInfoApi(data: { adAccountId: number, videoIds: number[] }) {
    return request(api + `/adq/v3/marketingAssets/getVideos`, {
        method: 'POST',
        data
    })
}



/**
 * 新增微信小程序
 * @param data 
 * @returns 
 */
export async function addWechatAppletApi(data: { appletId: string, appletName: string, appletLink: string, description: string }) {
    return request(api + `/adq/v3/wechatApplet/add`, {
        method: 'POST',
        data
    })
}

/**
 * 查询本地微信小程序列表
 * @param data 
 * @returns 
 */
export async function getWechatAppletApi(data: { pageNum: number, pageSize: number, appletName?: string, appletIdList?: string[], createBy?: number }) {
    return request(api + `/adq/v3/wechatApplet/list`, {
        method: 'POST',
        data
    })
}

/**
 * 删除微信小程序
 * @param data 
 * @returns 
 */
export async function delWechatAppletApi(id: number) {
    return request(api + `/adq/v3/wechatApplet/delById/${id}`, {
        method: 'DELETE'
    })
}

/**
 * 下载小程序上传模板
 * @returns 
 */
export async function downloadTemplateApi() {
    return request(api + `/adq/v3/wechatApplet/downloadTemplate`, {
        method: 'POST',
        responseType: 'blob'
    })
}

/**
 * 上传
 * @returns 
 */
export async function importExcelApi(data: any) {
    return request(api + `/adq/v3/wechatApplet/importExcel`, {
        method: 'POST',
        data
    })
}

/**
 * 修改微信小程序
 * @param data 
 * @returns 
 */
export async function updateWechatAppletApi(data: { appletId: string, appletName: string, appletLink: string, description: string, id: number }) {
    return request(api + `/adq/v3/wechatApplet/update`, {
        method: 'POST',
        data
    })
}


/**
 * 获取所有微信小程序列表
 * @param data 
 * @returns 
 */
export async function getWechatAppletAllApi(data: { appletName?: string, appletIdList?: string[] }) {
    return request(api + `/adq/v3/wechatApplet/listAll`, {
        method: 'POST',
        data
    })
}

/**
 * 获取详情
 * @param id 
 * @returns 
 */
export async function getWechatAppletDetailApi(id: number) {
    return request(api + `/adq/v3/wechatApplet/getById/${id}`, {
        method: 'GET'
    })
}




/**
 * 新增本地企微微信信息
 * @param data 
 * @returns 
 */
export async function addCorpWechatApi(data: { agentId: number, corpName: string, localCorpId: string, tencentCorpId: string }) {
    return request(api + `/adq/v3/tencentCorp/add`, {
        method: 'POST',
        data
    })
}

/**
 * 修改本地企微微信信息
 * @param data 
 * @returns 
 */
export async function modifyCorpWechatApi(data: { agentId: number, corpName: string, localCorpId: string, tencentCorpId: string }) {
    return request(api + `/adq/v3/tencentCorp/modify`, {
        method: 'PUT',
        data
    })
}

/**
 * 查询企微列表
 * @returns 
 */
export async function getLocalCorpListApi() {
    return request(api + `/adq/v3/tencentCorp/localCorpList`, {
        method: 'GET'
    })
}

/**
 * 查询本地企业微信列表
 * @param data 
 * @returns 
 */
export async function getCorpWechatApi(data: { pageNum: number, pageSize: number, corpName?: string, wechatIdList?: string[] }) {
    return request(api + `/adq/v3/tencentCorp/list`, {
        method: 'POST',
        data
    })
}



/**
 * 删除本地企业微信信息
 * @param data 
 * @returns 
 */
export async function delCorpWechatApi(id: number) {
    return request(api + `/adq/v3/corpWechat/delById/${id}`, {
        method: 'DELETE'
    })
}


/**
 * 获取填写所有企微列表 投放
 * @param data 
 * @returns 
 */
export async function getCorpWechatAllApi(data: { corpName?: string }) {
    return request(api + `/adq/v3/tencentCorp/listAll`, {
        method: 'POST',
        data
    })
}

/**
 * 获取企微详情
 * @param id 
 * @returns 
 */
export async function getCorpWechatDetailApi(params: { tencentCorpId: string }) {
    return request(api + `/adq/v3/tencentCorp/getByTencentCorpId`, {
        method: 'GET',
        params
    })
}


/**
 * 获取广告标签
 * @param data 
 * @returns 
 */
export async function getAdLabelApi(data: { accountId?: number }) {
    return request(api + `/adq/v3/launch/tools/getAdLabel`, {
        method: 'POST',
        data
    })
}

/**
 * 获取游戏列表
 * @param data 
 * @returns 
 */
export async function getGameLibraryListApi(data: { pageNum: number, pageSize: number, gameName?: string, idList?: number[], gameType?: string }) {
    return request(api + `/adq/v3/gameLibrary/pageList`, {
        method: 'POST',
        data
    })
}

/**
 * 所有游戏列表
 * @param data 
 * @returns 
 */
export async function getGameLibraryApi(data: { gameName?: string, idList?: number[], gameType?: string }) {
    return request(api + `/adq/v3/gameLibrary/listAll`, {
        method: 'POST',
        data
    })
}

/**
 * 新增游戏
 * @param data 
 * @returns 
 */
export async function addGameApi(data: { appId: string, gameName: string, gameType: string, id?: number }) {
    return request(api + `/adq/v3/gameLibrary/add`, {
        method: 'POST',
        data
    })
}

/**
 * 删除游戏
 * @param id 
 * @returns 
 */
export async function delGameApi(id: number) {
    return request(api + `/adq/v3/gameLibrary/delById/${id}`, {
        method: 'DELETE'
    })
}

/**
 * 获取游戏详情
 * @param id 
 * @returns 
 */
export async function getGameLibraryDetailApi(id: number) {
    return request(api + `/adq/v3/gameLibrary/getById/${id}`, {
        method: 'GET'
    })
}

/**
 * 获取游戏详情
 * @param wxGameAppId 
 * @returns 
 */
export async function getGameLibraryAppIdDetailApi(wxGameAppId: number) {
    return request(api + `/adq/v3/gameLibrary/getByAppId/${wxGameAppId}`, {
        method: 'GET'
    })
}


/**
 * 获取弹幕
 * @param data 
 * @returns 
 */
export async function getBarrageRecommendListApi(params: { adAccountId?: number, taskType?: 'GAME' | 'NOVEL' }) {
    // return request(api + `/adq/v3/launch/tools/creative/tools/barrage`, {
    return request(api + `/adq/v3/launch/tools/creative/tools/barrageRecommend`, {
        method: 'GET',
        params
    })
}


/**
 * 账户资产组分页查询
 * @param params 
 * @returns 
 */
export async function getAccountAssetsGroupListApi(data: { accountGroupName?: string, authMainAccountIds?: number[], authType?: string, pageNum: number, pageSize: number }) {
    return request(api + `/adq/v3/marketingAssets/accountAssetsGroup/pageList`, {
        method: 'POST',
        data
    })
}

/**
 * 所有账户资产共享组
 * @param data 
 * @returns 
 */
export async function getAccountAssetsGroupListAllApi(data: { accountGroupName?: string, authMainAccountIds?: number[] }) {
    return request(api + `/adq/v3/marketingAssets/accountAssetsGroup/ListAll`, {
        method: 'POST',
        data
    })
}


/**
 * 账户资产组修改（只能改名字）
 * @param data 
 * @returns 
 */
export async function updateAccountAssetsGroupApi(data: { accountGroupId: number, accountGroupName: string }) {
    return request(api + `/adq/v3/marketingAssets/accountAssetsGroup/update`, {
        method: 'POST',
        data
    })
}

/**
 * 账户资产组取消授权
 * @param data 
 * @returns 
 */
export async function revokeAuthAccountAssetsGroupApi(data: { accountAssetsGroupId: number, accountId: number[], assetId?: number }) {
    return request(api + `/adq/v3/marketingAssets/accountAssetsGroup/revokeAuth`, {
        method: 'POST',
        data
    })
}

/**
 * 删除账户组
 * @param data 
 * @returns 
 */
export async function delAuthAccountAssetsGroupApi(data: { id: number }) {
    return request(api + `/adq/v3/marketingAssets/accountAssetsGroup/delete/${data.id}`, {
        method: 'DELETE',
    })
}

/**
 * 账户资产组创建
 * @param data 
 * @returns 
 */
export async function createAccountAssetsGroupApi(data: { accountGroupId?: number, accountGroupName: string, authMainAccountId: number, authType: string }) {
    return request(api + `/adq/v3/marketingAssets/accountAssetsGroup/create`, {
        method: 'POST',
        data
    })
}


/**
 * 查询被授权的账户
 * @param data 
 * @returns 
 */
export async function getAccountAssetsGroupAccountListApi(data: { groupId: number }) {
    return request(api + `/adq/v3/marketingAssets/accountAssetsGroup/authAccountList/${data.groupId}`, {
        method: 'GET'
    })
}


/**
 * 账户资产授权
 * @param data 
 * @returns 
 */
export async function authAccountAssetsGroupAccountApi(data: { accountAssetsGroupId: number, accountId: number[], assetId?: number, assetName?: string }) {
    return request(api + `/adq/v3/marketingAssets/accountAssetsGroup/auth`, {
        method: 'POST',
        data
    })
}

/**
 * 批量授权
 * @param data 
 * @returns 
 */
export async function batchAuthAccountAssetsGroupAccountApi(data: { accountAssetsGroupId: number, accountId: number[], assetsDTOS: { assetId: number, assetName: string }[] }) {
    return request(api + `/adq/v3/marketingAssets/accountAssetsGroup/batchAuth`, {
        method: 'POST',
        data
    })
}

/**
 * 同步素材
 * @param data 
 * @returns 
 */
export async function syncMediaImageApi({ type, ...data }: { accountIds: number[], createTimeMin: string, createTimeMax: string, type: 'image' | 'video' }) {
    if (type === 'image') {
        return request(api + `/adq/v3/mediaImage/syncImage`, {
            method: 'POST',
            data
        })
    }
    return request(api + `/adq/v3/mediaVideo/syncVideo`, {
        method: 'POST',
        data
    })
}


/**
 * 获取文案库列表
 * @param data 
 * @returns 
 */
export async function getCopyWritingListApi(data: { category?: string, content?: string, createBy?: number, pageNum: number, pageSize: number }) {
    return request(api + `/adq/copyWriting/pageList`, {
        method: 'POST',
        data
    })
}

/**
 * 新增修改文案
 * @param data 
 * @returns 
 */
export async function copyWritingApi(data: { category: string, contentList?: string[], content?: string, id?: number }) {
    if (data?.id) {
        return request(api + `/adq/copyWriting/update`, {
            method: 'POST',
            data
        })
    }
    return request(api + `/adq/copyWriting/addBatch`, {
        method: 'POST',
        data
    })
}

/**
 * 删除
 * @param id 
 * @returns 
 */
export async function delCopyWritingApi(id: number) {
    return request(api + `/adq/copyWriting/delById/${id}`, {
        method: 'DELETE',
    })
}

/**
 * 批量删除
 * @param ids 
 * @returns 
 */
export async function delsCopyWritingApi(ids: number[]) {
    return request(api + `/adq/copyWriting/batchDelByIds`, {
        method: 'DELETE',
        data: ids
    })
}

export type ApplicationTypeProps = 'IOS' | 'ANDROID'
export interface GetApplicationListProps {
    pageNum: number,
    pageSize: number,
    createBy?: number,
    applicationId?: string
    name?: string
    type?: ApplicationTypeProps
}

/**
 * 查询本地推广应用列表
 * @param data 
 * @returns 
 */
export async function getApplicationListApi(data: GetApplicationListProps) {
    return request(api + `/adq/promote/application/list`, {
        method: 'POST',
        data
    })
}

/**
 * 查询本地推广全部应用列表
 * @param data 
 * @returns 
 */
export async function getApplicationAllApi(data: Omit<GetApplicationListProps, 'pageNum' | 'pageSize'>) {
    return request(api + `/adq/promote/application/listAll`, {
        method: 'POST',
        data
    })
}

export interface AddApplicationProps {
    applicationId: number,
    name: string,
    type: ApplicationTypeProps
    id?: number
}

/**
 * 新增推广应用
 * @param data 
 * @returns 
 */
export async function addApplicationApi(data: AddApplicationProps) {
    return request(api + `/adq/promote/application/add`, {
        method: 'POST',
        data
    })
}


/**
 * 修改推广应用
 * @param data 
 * @returns 
 */
export async function updateApplicationApi(data: Required<AddApplicationProps>) {
    return request(api + `/adq/promote/application/update`, {
        method: 'POST',
        data
    })
}

/**
 * 删除本地推广应用
 * @param id 
 * @returns 
 */
export async function delApplicationApi(id: number) {
    return request(api + `/adq/promote/application/delById/${id}`, {
        method: 'DELETE',
    })
}

/**
 * 应用详情
 * @param id 
 * @returns 
 */
export async function getApplicationDetailApi(id: number) {
    return request(api + `/adq/promote/application/getById/${id}`, {
        method: 'GET'
    })
}


export interface GetCustomerServiceGroupListProps {
    pageNum: number,
    pageSize: number,
    accountId?: string,
    csgroupName?: string, // 客服组名称
    tencentCorpId?: string, // 企业微信ID
    parentId?: number, // 父级ID
    type?: 0 | 1, // 类型 0:客服组集,1:客服组,
    policyId?: number, // 轮换策略ID
    closeSwitch?: boolean
}
/**
 * 查询企业微信组件客服组
 * @param data 
 * @returns 
 */
export async function getCustomerServiceGroupListApi(data: GetCustomerServiceGroupListProps) {
    return request(api + `/adq/localCorpCsgroup/listOfPage`, {
        method: 'POST',
        data
    })
}

/**
 * 客服组-按类型查询(不分页, 类型非必传, 下拉筛选框使用)
 * @param params 
 * @returns 
 */
export async function getLocalCorpCsgroupListAllApi(params: { accountId?: number, type?: 0 | 1 }) {
    return request(api + `/adq/localCorpCsgroup/listOfType`, {
        method: 'GET',
        params
    })
}

/**
 * 已关联腾讯客服组
 * @param params 
 * @returns 
 */
export async function getRelationGroupListApi(params: { localCorpCsgroupId: number }) {
    return request(api + `/adq/localCorpCsgroup/getRelationGroup`, {
        method: 'GET',
        params
    })
}

export interface GetCustomerServiceGroupUserListProps {
    pageNum: number, // 页码
    pageSize: number, // 页大小
    localCorpId?: number,
    localCsgroupId?: number, // 企业微信ID
    localCorpUserName?: string, // 客服组成员名称
    poolType?: 'BLOCKLIST' | 'OFFLINE' | 'ONLINE' | 'WAITING' | 'WARRING', // 客服组成员状态
}

/**
 * 客服组成员-分页查询
 * @param data 
 * @returns 
 */
export async function getLocalCorpCsgroupUserListApi(data: GetCustomerServiceGroupUserListProps) {
    return request(api + `/adq/localCorpCsgroup/user/listOfPage`, {
        method: 'POST',
        data
    })
}

/**
 * 用户日志
 * @param data 
 * @returns 
 */
export async function getUserlogListApi(data: { pageNum: number, pageSize: number, id: number }) {
    return request(api + `/adq/localCorpCsgroup/userLog/listOfPage`, {
        method: 'POST',
        data
    })
}

/**
 * 所有成员
 * @param data 
 * @returns 
 */
export async function getLocalCorpCsgroupUserAllListApi(data: { poolType?: 'BLOCKLIST' | 'OFFLINE' | 'ONLINE' | 'WAITING' | 'WARRING', localCsgroupId: number, localCorpUserName?: string }) {
    return request(api + `/adq/localCorpCsgroup/user/all`, {
        method: 'POST',
        data
    })
}

export interface AddLocalCorpCsgroupUserListProps {
    localCsgroupId: number,
    tencentCorpId: string,
    tencentCorpUserIdList: string[]
}

/**
 * 新增客服组成员
 * @param data 
 * @returns 
 */
export async function addLocalCorpCsgroupUserListApi(data: AddLocalCorpCsgroupUserListProps) {
    return request(api + `/adq/localCorpCsgroup/user/add`, {
        method: 'POST',
        data
    })
}

/**
 * 删除客服组成员
 * @param data 
 * @returns 
 */
export async function delLocalCorpCsgroupUserApi(data: { idList: number[] }) {
    return request(api + `/adq/localCorpCsgroup/user/deleteBatch`, {
        method: 'DELETE',
        data
    })
}


/**
 * 修改客服号
 * @param data 
 * @returns 
 */
export async function modifyLocalCorpCsgroupUserApi(data: { idList: number[], limitAddFansOfDay: number, poolType?: 'BLOCKLIST' | 'OFFLINE' | 'ONLINE' | 'WAITING' | 'WARRING' }) {
    return request(api + `/adq/localCorpCsgroup/user/modifyBatch`, {
        method: 'PATCH',
        data
    })
}

export interface updateCustomerServiceGroupProps {
    adAccountId: number,
    tencentCorpId: string,
    groupId: number,
    groupName: string,
    userIdList: string[]
}

export interface AddLocalCorpCsgroupProps {
    csgroupName: string, // 客服组名称
    tencentCorpId: string,
    type: 0 | 1,  // 类型 0:客服组集,1:客服组,
    parentId?: number, // 父级ID
    policyId?: number, // 轮换策略ID
}
/**
 * 新增客服组
 * @param data 
 * @returns 
 */
export async function addLocalCorpCsgroupApi(data: AddLocalCorpCsgroupProps) {
    return request(api + `/adq/localCorpCsgroup/add`, {
        method: 'POST',
        data
    })
}


/**
 * 开关更新接口
 * @param params 
 * @returns 
 */
export async function closeSwitchUpdateApi(params: { id: number, closeSwitch: boolean }) {
    return request(api + `/adq/localCorpCsgroup/close/switch/update`, {
        method: 'PATCH',
        params
    })
}

/**
 * 修改客服组
 * @param data 
 * @returns 
 */
export async function modifyLocalCorpCsgroupApi(data: AddLocalCorpCsgroupProps) {
    return request(api + `/adq/localCorpCsgroup/modifyById`, {
        method: 'PATCH',
        data
    })
}


/**
 * 服务商解密同步
 * @param params 
 * @returns 
 */
export async function putUserDecodeApi(params: { localCsgroupId: number }) {
    return request(api + `/adq/localCorpCsgroup/userDecode/sync`, {
        method: 'GET',
        params
    })
}

/**
 * 服务商解密查询
 * @param data 
 * @returns 
 */
export async function getUserDecodeListApi(data: { localCsgroupId: number, pageNum: number, pageSize: number }) {
    return request(api + `/adq/localCorpCsgroup/userDecode/list`, {
        method: 'POST',
        data
    })
}

export interface getWechatPagesCsgroupUserProps {
    adAccountId: number,
    tencentCorpId: string,
    corpName: string,
    departmentId?: number
}
/**
 * 获取企业微信组件客服组成员
 * @param data 
 * @returns 
 */
export async function getWechatPagesCsgroupUserApi(data: getWechatPagesCsgroupUserProps) {
    return request(api + `/adq/v3/launch/tools/wechatPagesCsgroupUser/get`, {
        method: 'POST',
        data
    })
}

/**
 * 获取企业部门列表
 * @param data 
 * @returns 
 */
export async function getCorpDepartmentListApi(params: { corpName: string }) {
    return request(api + `/adq/v3/launch/tools/corpDepartmentList/get`, {
        method: 'POST',
        params
    })
}

export interface GetTencentCorpCsgroupListProps {
    groupName?: string, // 客服组名称
    tencentCorpId?: string,
    pageNum: number, // 页码
    pageSize: number, // 页大小
}

/**
 * 腾讯客服组列表查询
 * @param data 
 * @returns 
 */
export async function getTencentCorpCsgroupListApi(data: GetTencentCorpCsgroupListProps) {
    return request(api + `/adq/tencentCorpCsgroup/listOfPage`, {
        method: 'POST',
        data
    })
}

/**
 * 同步腾讯客服组
 * @param data 
 * @returns 
 */
export async function syncencentCorpCsgroupApi(data: { tencentCorpId: string, accountId: number, groupId: number }) {
    return request(api + `/adq/tencentCorpCsgroup/sync`, {
        method: 'POST',
        data
    })
}

/**
 * 腾讯客服组-查询组内成员
 * @param params 
 * @returns 
 */
export async function getUserListListApi(params: { groupId: number }) {
    return request(api + `/adq/tencentCorpCsgroup/userList`, {
        method: 'GET',
        params
    })
}

export interface AddTencentCorpCsgroupProps {
    accountId: number, // 账户ID
    tencentCorpId: string, // 企业微信ID
    groupName: string, // 客服组名称
    tencentCorpUserIds: string[], // 企业微信成员ID
}

/**
 * 腾讯客服组-新增
 * @param data 
 * @returns 
 */
export async function addTencentCorpCsgroupApi(data: GetTencentCorpCsgroupListProps) {
    return request(api + `/adq/tencentCorpCsgroup/add`, {
        method: 'POST',
        data
    })
}

/**
 * 绑定本地客服组
 * @param data 
 * @returns 
 */
export async function bandTencentCorpCsgroupApi(data: { groupId: number, localCsgroupId?: number }) {
    return request(api + `/adq/tencentCorpCsgroup/modifyById`, {
        method: 'PATCH',
        data
    })
}

/**
 * 查询企微关系列表
 * @param params 
 * @returns 
 */
export async function getCorpRelationListApi(data: { adAccountId: number }) {
    return request(api + `/adq/corpRelation/listOfPage`, {
        method: 'POST',
        data
    })
}

/**
 * 删除企微关系
 * @param id 
 * @returns 
 */
export async function delCorpRelationApi(id: number) {
    return request(api + `/adq/corpRelation/delById/${id}`, {
        method: 'DELETE'
    })
}

/**
 * 新增企微关系
 * @param params 
 * @returns 
 */
export async function addCorpRelationListApi(data: { adAccountId: number, corpId: string, corpName: string, tencentCorpId: string }) {
    return request(api + `/adq/corpRelation/add`, {
        method: 'POST',
        data
    })
}


export interface AddUserRotatePolicyProps {
    policyName: string              // 策略名称
    addCostCalculationCycle?: number // 加粉成本的计算周期（/分钟，必须 >= 20，且必须是 10 的整数倍数）
    addCostException?: number       // 加粉成本异常值 (单位：/分)
    maxAddFansCount?: number        // 单号单日最大加粉数量
    minAddFansCount?: number        // 单号单日最大加粉数量，默认 20，加粉数少于该值永远不触发风控
    onlineCount?: number            // 组内客服号在线数量
    rollingCustomerTime?: number    // 客服组内滚动客服号的周期（/分钟，必须 >= 10）
    id?: number
}
/**
 * 客服组成员轮换策略-新增
 * @param params 
 * @returns 
 */
export async function addUserRotatePolicyApi(data: AddUserRotatePolicyProps) {
    return request(api + `/adq/localCorpCsgroup/userRotatePolicy/add`, {
        method: 'POST',
        data
    })
}

/**
 * 修改策略
 * @param data 
 * @returns 
 */
export async function modifyUserRotatePolicyApi(data: AddUserRotatePolicyProps) {
    return request(api + `/adq/localCorpCsgroup/userRotatePolicy/modifyById`, {
        method: 'PATCH',
        data
    })
}

/**
 * 客服组成员轮换策略-分页查询
 * @param data 
 * @returns 
 */
export async function getUserRotatePolicyListApi(data: { pageNum: number, pageSize: number, policyName?: string }) {
    return request(api + `/adq/localCorpCsgroup/userRotatePolicy/listOfPage`, {
        method: 'POST',
        data
    })
}

/**
 * 所有客服组成员轮换策略
 * @param data 
 * @returns 
 */
export async function getUserRotatePolicyAllListApi(data: { policyName?: string }) {
    return request(api + `/adq/localCorpCsgroup/userRotatePolicy/all`, {
        method: 'POST',
        data
    })
}

/**
 * 获取所有企微列表
 * @returns 
 */
export async function getCorpListAllApi() {
    return request(api + `/adq/corpRelation/corpListAll`, {
        method: 'GET',
    })
}

export interface AddPageCustomerGroupProps {
    landingPageList: { [x: string]: any }[], // 落地页
    localCsgroupId: string
}
/**
 * 新增落地页客服关系
 * @param data 
 * @returns 
 */
export async function addPageCustomerGroupApi(data: AddPageCustomerGroupProps) {
    return request(api + `/adq/localCorpCsgroup/landingPage/add`, {
        method: 'POST',
        data
    })
}

/**
 * 修改落地页客服关系
 * @param data 
 * @returns 
 */
export async function modifyPageCustomerGroupApi(data: { localCsgroupId: number, pageId: number, pageType: string }) {
    return request(api + `/adq/localCorpCsgroup/landingPage/modifyById`, {
        method: 'PATCH',
        data
    })
}


/**
 * 新增原生落地页客服关系
 * @param data 
 * @returns 
 */
export async function addLandingPageCustomerGroupApi(data: AddPageCustomerGroupProps) {
    return request(api + `/adq/localCorpCsgroup/wechat/landingPage/add`, {
        method: 'POST',
        data
    })
}

/**
 * 修改落地页客服关系
 * @param data 
 * @returns 
 */
export async function modifyLandingPageCustomerGroupApi(data: { localCsgroupId: number, pageId: number }) {
    return request(api + `/adq/localCorpCsgroup/wechat/landingPage/modifyById`, {
        method: 'PATCH',
        data
    })
}

export interface GetPageCustomerGroupListProps {
    pageNum: number,
    pageSize: number,
    pageId?: string,
    pageName?: string
}
/**
 * 查询落地页客服关系
 * @param data 
 * @returns 
 */
export async function getPageCustomerGroupListApi(data: GetPageCustomerGroupListProps) {
    return request(api + `/adq/localCorpCsgroup/landingPage/listOfPage`, {
        method: 'POST',
        data
    })
}

/**
 * 原生落地页客服关系
 * @param data 
 * @returns 
 */
export async function getLandingPageCustomerGroupListApi(data: GetPageCustomerGroupListProps) {
    return request(api + `/adq/localCorpCsgroup/wechat/landingPage/listOfPage`, {
        method: 'POST',
        data
    })
}


export interface GetCreativeComponentProps {
    pageNum: number,
    pageSize: number,
    adAccountId?: number,
    componentId?: string[],
    componentSubType?: string[]
    componentType?: string[]
    createTimeMin?: string
    createTimeMax?: string
    generationType?: string[]
    imageId?: string[]
    videoId?: string[]
    isDeleted?: boolean
    potentialStatus?: string
    activeKey?: string
    componentCustomName?: string
    sortColumn?: string
    sortAsc?: boolean
    costStartTime?: string
    costEndTime?: string
}

/**
 * 分页查询创意组件
 * @param data 
 * @returns 
 */
export async function getCreativeComponentListApi(data: GetCreativeComponentProps) {
    return request(api + `/adq/creative/component/listOfPage`, {
        method: 'POST',
        data
    })
}

/**
 * 分页查询创意组件 + 数据
 * @param data 
 * @returns 
 */
export async function getCreativeComponentDataListApi(data: GetCreativeComponentProps) {
    return request(api + `/material/componentData/listOfPage`, {
        method: 'POST',
        data
    })
}

interface GetComponentSharingProps {
    adAccountId: number
    componentId: number
    pageNum: number,
    pageSize: number,
    isDeleted?: boolean
}

/**
 * 查询组件共享账号
 * @param data 
 * @returns 
 */
export async function getComponentSharingApi(data: GetComponentSharingProps) {
    return request(api + `/adq/creative/component/getComponentSharing`, {
        method: 'POST',
        data
    })
}
interface UpdateComponentSharingProps {
    adAccountId: number
    componentId: number
    sharingAccountIds: number[]
    sharedAccountType: string // ADVERTISER 部分共享、ORGANIZATION 全部共享
}

/**
 * 修改共享状态
 * @param data 
 * @returns 
 */
export async function updateComponentSharingApi(data: UpdateComponentSharingProps) {
    return request(api + `/adq/creative/component/updateComponentSharing`, {
        method: 'POST',
        data
    })
}

export interface CreativeComponentDetailDTOS {
    materialId?: string,
    componentSubType: string
    componentType?: string, //'image' | 'imageList' | 'video' | 'videoList' | 'description',
    materialIdList?: string[]
    coverUrl?: string
    text?: string
}

export interface AddBatchCreativeComponent {
    adAccountId: number,
    creativeComponentDetailDTOS: CreativeComponentDetailDTOS[]
}
/**
 * 批量创建创意组件
 * @param data 
 * @returns 
 */
export async function addBatchCreativeComponentApi(data: AddBatchCreativeComponent) {
    return request(api + `/adq/creative/component/addBatch`, {
        method: 'POST',
        data
    })
}

/**
 * 删除组件
 * @param params 
 * @returns 
 */
export async function delComponentApi({ componentId, ...params }: { adAccountId: number, componentId: number[] }) {
    return request(api + `/adq/creative/component/deleteBatch`, {
        method: 'DELETE',
        params,
        data: componentId
    })
}

/**
 * 同步组件
 * @param param0 
 * @returns 
 */
export async function syncComponentApi(data: { accountIds: number[], startTime: string, endTime: string }) {
    return request(api + `/adq/creative/component/syncBatch`, {
        method: 'PUT',
        data
    })
}