import { request } from 'umi';
import { api, erpApi } from '../api';
import { Paging, SortProps } from './rankingList';
let wapi = api + '/gameData'
let mapi = api + '/manage'

export interface PromotionDataDay extends Paging, SortProps {
    accountId?: number,   // 推广账号ID
    accountName?: string, // 推广账号名称
    accountType?: string, // 投放媒体
    agentId?: number,     // 渠道ID
    agentKey?: string,    // 渠道标识
    agentName?: string,   // 渠道名称
    classify?: number,    // 游戏应用类型
    costBeginDate?: string, // 消耗开始时间
    costEndDate?: string,   // 消耗结束时间
    cpName?: string,      // CP名称
    gameId?: number,      // 游戏ID
    gameName?: string,    // 游戏名称
    pitcherId?: number,   // 投手ID
    pitcherName?: string, // 投手名称
    projectId?: number,   // 计划ID
    projectName?: string, // 计划名称
    promotionId?: number, // 广告ID
    promotionName?: string, // 广告名称
    sourceSystem?: string,  // SDK来源
    status?: string     //广告状态
    dynamicCreativeId?: number // 创意ID
    dynamicCreativeName?: string // 创意名称
}
/**
 * 头条广告监控数据
 * @param data 
 * @returns 
 */
export async function getPromotionDataDatListApi(data: PromotionDataDay) {
    return request(wapi + `/promotionData/day`, {
        method: 'POST',
        data
    });
}

/**
 * 头条广告监控数据总计
 * @param data 
 * @returns 
 */
export async function getPromotionDataDatTotalApi(data: PromotionDataDay) {
    return request(wapi + `/promotionData/total`, {
        method: 'POST',
        data
    });
}

/**
 * 头条广告每日监控
 * @param data 
 * @returns 
 */
export async function getPromotionDataDayListApi(data: PromotionDataDay) {
    return request(wapi + `/promotionData/day/list`, {
        method: 'POST',
        data
    });
}

/**
 * 头条广告每日监控总计
 * @param data 
 * @returns 
 */
export async function getPromotionDataDayTotalApi(data: PromotionDataDay) {
    return request(wapi + `/promotionData/day/listTotal`, {
        method: 'POST',
        data
    });
}


/**
 * 腾讯广告监控数据
 * @param data 
 * @returns 
 */
export async function getPromotionDataTencentListApi(data: PromotionDataDay) {
    return request(wapi + `/promotionData/tencent/day`, {
        method: 'POST',
        data
    });
}


/**
 * 腾讯广告监控数据总计
 * @param data 
 * @returns 
 */
export async function getPromotionDataTencentTotalApi(data: PromotionDataDay) {
    return request(wapi + `/promotionData/tencent/total`, {
        method: 'POST',
        data
    });
}


/**
 * 腾讯广告监控数据
 * @param data 
 * @returns 
 */
export async function getDynamicTencentListApi(data: PromotionDataDay) {
    return request(wapi + `/creativeData/tencent/day`, {
        method: 'POST',
        data
    });
}


/**
 * 腾讯广告监控数据总计
 * @param data 
 * @returns 
 */
export async function getDynamicTencentTotalApi(data: PromotionDataDay) {
    return request(wapi + `/creativeData/tencent/total`, {
        method: 'POST',
        data
    });
}


/**
 * 腾讯广告每日监控
 * @param data 
 * @returns 
 */
export async function getPromotionDataTencentDayListApi(data: PromotionDataDay) {
    return request(wapi + `/promotionData/tencent/day/list`, {
        method: 'POST',
        data
    });
}
/**
 * 腾讯广告每日总计监控
 * @param data 
 * @returns 
 */
export async function getPromotionDataTencentDayTotalApi(data: PromotionDataDay) {
    return request(wapi + `/promotionData/tencent/day/listTotal`, {
        method: 'POST',
        data
    });
}

export interface EditAdqAdgroupsProps {
    /** 广告组id列表 */
    adgroupIds: number[],
    /** 广告名称 */
    adgroupName?: string,
    /** 出价 */
    adgroupsUpdateBidAmountDTO?: {
        bidAmount: number,  // 出价
        bidMode: string,    // 出价方式
        bidStrategy: string,// 出价策略
        optimizationGoal: string,  // 出价目标
    },
    /** 排期 */
    adgroupsUpdateDatetimeDTO?: {
        beginDate: string,
        endDate?: string,
        firstDayBeginTime?: string,
        timeSeries?: string
    },
    /** 深度优化 */
    deepConversionSpec?: {
        deepConversionType: string,
        deepConversionBehaviorSpec?: {
            bidAmount: number,
            goal: string
        },
        deepConversionWorthAdvancedSpec?: {
            expectedRoi: number,
            goal: string
        },
        deepConversionWorthSpec?: {
            expectedRoi: number,
            goal: string
        }
    },
    /** 启停状态 */
    configuredStatus?: string
}

/**
 * 腾讯广告启停
 * @param data 
 * @returns 
 */
export async function newEditAdqAdgroupsDataApi(data: EditAdqAdgroupsProps) {
    return request(erpApi + `/adq/adgroups/configStatus/update/batch`, {
        method: 'POST',
        data
    });
}

export interface ModifyStatusBatchProps {
    accountAdgroupMaps: string[]
    suspend: boolean
}
/**
 * 批量修改创意信息
 * @param data 
 * @returns 
 */
export async function updateBatchDynamicCreativesInfoApi(data: ModifyStatusBatchProps) {
    return request(api + '/adq/adgroup/updateBatchDynamicCreativesInfo', {
        method: 'PUT',
        data
    });
}

export interface EditTTAdgroupsProps {
    suspend: boolean
    accountAdgroupMaps: string[] // "广告id和广告账号id的映射关系字符串 (逗号拼接)"
}
export async function newEditTTAdgroupsDataApi(data: EditTTAdgroupsProps) {
    return request(erpApi + `/oceanengine/ad/modifyStatusBatch`, {
        method: 'POST',
        data
    });
}


/************************游戏广告策略*****************************/
export interface GetPolicyConfigProps extends Paging {
    gameId?: number,    // 子游戏维度
    isStart?: boolean   /// 是否启用
    mediaType?: number  // 媒体类型 1-腾讯;2-头条
    ruleName?: string
}

/**
 * 规则列表
 * @param data 
 * @returns 
 */
export async function getPolicyConfigListApi(data: EditAdqAdgroupsProps) {
    return request(mapi + `/ad/policy/config/list`, {
        method: 'POST',
        data
    });
}

export interface ConfigRuleProps {
    // 规则下的账号白名单有效时间类型：1-当日有效（自然日）;2-长期有效
    accountValidTime: number,
    // 规则下的账号白名单
    accountWhitelist: number[],
    // 规则下的广告白名单有效时间类型：1-当日有效（自然日）;2-长期有效
    adValidTime: number,
    // 规则下的广告白名单
    adWhitelist: number[],
    // 通知总次数
    alarmCount: number
    // 通知频率:单位:分钟/次
    alarmFrequency: number
    // 告警方式:1-短信;2-电话;3-钉钉
    alarmType: number
    // 数据数据巡视周期:1-实时巡视周期
    dataVisitsPeriod: number
    // 部门类型:1-游戏投放
    department: number
    // 执行范围:1-所有广告（不含删除）;2-投放中;3-暂停投放;4-预算不足
    executeScope: number
    // 游戏ID(子游戏维度)
    gameId: number
    // 是否启用
    isStart: boolean
    // 媒体类型:1-腾讯;2-头条
    mediaType: number
    // 操作维度:1-广告
    operateDimension: number
    // 操作类型:1-仅告警通知;2-暂停广告;3-启动广告;4-增加预算;5-减少预算;6-广告置顶标黄;7-广告置顶标红
    operateType: number

    // 规则条件(最多可同事设置5个指标条件)
    ruleCondition: {
        // 1-大于;2-大于等于;3-等于;4-小于等于;5-小于
        conditionType: number
        // 具体数值
        dataNum: number
        /**
         * 指标类型：1-消耗;2-预算;3-点击率;4-ecpm(千次曝光成本);5-注册;6-注册成本(消耗/注册人数);7-付费人数;8-付费率(付费人数/注册人数)
            9-付费成本(消耗/付费人数);10-arpu(付费金额/注册人数);11-ROI1(首日付费金额/消耗);12-ROI2(?/消耗);13-ROI3;
            14-ROI4;15-ROI5;16-ROI6;17-ROI7;18-LTV1;19-LTV2;20-LTV3;21-LTV4;22-LTV5;23-LTV6;24-LTV7;
         */
        dataType: number
        /**
         * 监控的数据时间段类型：1-今日;2-过去3天（包括今日）;3-过去5天（包括今日）;4-过去7天（包括今日）;
        5-过去3天（不包括今日）;6-过去5天（不包括今日）;7-过去7天（不包括今日）;
        8-广告开始消耗首日（0）;9-广告开始消耗（累计3天）;10-广告开始消耗（累计5天）;11-广告开始消耗（累计7天）;
         */
        monitorTimeType: number
        id?: number
    }
    // 规则维度:1-默认;2-渠道;3-账号;4-广告
    ruleDimension: number
    ruleName: string
    // 规则类型:1-个人规则
    ruleType: number
    // 生效范围(依据规则维度变化):0（默认维度：当前创建人的所有广告）;其他（对应规则维度的ID集合）
    effectiveScope?: number[]
    id?: number
}

/**
 * 新增修改
 * @param data 
 * @returns 
 */
export async function configRuleApi(data: ConfigRuleProps) {
    return request(mapi + `/ad/policy/config/add/or/update`, {
        method: 'POST',
        data
    });
}

/**
 * 删除策略
 * @param ids 
 * @returns 
 */
export async function delConfigRuleApi(ids: string) {
    return request(mapi + `/ad/policy/config/delete/${ids}`, {
        method: 'DELETE'
    });
}

export interface ConfigHandleProps {
    accountValidTime: number,
    accountWhitelist: number[],
    adValidTime: number,
    adWhitelist: number[],
    ids: number,
}
/**
 * 游戏广告策略配置批量操作:添加白名单;启用;暂停
 * @param ids 
 * @returns 
 */
export async function configHandleApi(data: ConfigHandleProps) {
    return request(mapi + `/ad/policy/config/batch/operation`, {
        method: 'POST',
        data
    });
}

/**
 * 启用 暂停
 * @param data 
 * @returns 
 */
export async function configEnableApi(data: { ids: number[], isStart: boolean }) {
    return request(mapi + `/ad/policy/config/batch/start`, {
        method: 'POST',
        data
    });
}