import { api } from '../api'
import { request } from 'umi'
/***********告警接口**************/

export interface RuleProps {
    field: string,
    condition: '>' | '>=' | '<' | '<=' | '=',
    value: string
}
export interface AddSysWarningRuleProps {
    // 1：默认规则；0：非默认规则；默认规则仅能创建一条
    defaultRule: 0 | 1,
    // 1：规则启用；0：规则禁用
    enable: 0 | 1,
    // 通知频率（分钟）,最少五分钟
    notifyFrequency: number,
    // 修改ID 
    ruleId: number,
    // 规则名称
    ruleName: string,
    // 规则列表
    rules: {
        rule: RuleProps[]
    }[],
    warningType: Array<'SMS' | 'DING_TALK'>
}
/** 设置预警 */
export async function addSysWarningRuleApi(data: AddSysWarningRuleProps) {
    return request(`${api}/adq/sysWarningRule/add`, {
        method: 'POST',
        data
    })
}
/** 修改预警 */
export async function editSysWarningRuleApi(data: AddSysWarningRuleProps) {
    return request(`${api}/adq/sysWarningRule/modify`, {
        method: 'POST',
        data
    })
}


/**
 * 告警规则下的广告列表
 * @param ruleId 
 * @returns 
 */
export async function getSysWarningRuleApi(ruleId: number) {
    return request(`${api}/adq/sysWarningRule/adConfigDetail/${ruleId}`, {
        method: 'GET'
    })
}

/**
 * 删除告警规则
 * @param ruleIds 
 * @returns 
 */
export async function delSysWarningRuleApi(ruleIds: string) {
    return request(`${api}/adq/sysWarningRule/delete/${ruleIds}`, {
        method: 'POST'
    })
}


export interface DelAdSysWarningRuleProps {
    accountId: number, 
    adgroupId: number, 
    ruleId: number
}
/**
 * 删除告警规则下的广告
 * @param data 
 * @returns 
 */
export async function delAdSysWarningRuleApi(data: DelAdSysWarningRuleProps) {
    return request(`${api}/adq/sysWarningRule/removeAdgroup/${data.accountId}/${data.adgroupId}/${data.ruleId}`, {
        method: 'PUT'
    })
}

/**
 * 删除黑名单列表广告
 * @param data 
 * @returns 
 */
export async function delAdSysWarningRuleBlackApi(data: DelAdSysWarningRuleProps) {
    return request(`${api}/adq/sysWarningRule/removeBlackList/${data.accountId}/${data.adgroupId}/${data.ruleId}`, {
        method: 'PUT'
    })
}

/**
 * 删除账号
 * @param data 
 * @returns 
 */
export async function removeAccountApi(data: DelAdSysWarningRuleProps) {
    return request(`${api}/adq/sysWarningRule/removeAccount/${data.accountId}/${data.ruleId}`, {
        method: 'DELETE'
    })
}

/**
 * 告警规则列表
 * @param params 
 * @returns 
 */
export async function getSysWarningRuleListApi(params: { ruleName?: string }) {
    return request(`${api}/adq/sysWarningRule/list`, {
        method: 'GET',
        params
    })
}

export interface AddAdsProps {
    accountId: number,
    adgroupId: number,
    campaignId: number
}
export interface ModifySysWarningRuleProps {
    addAds: AddAdsProps,
    ruleId: number
}
/**
 * 广告下设置规则
 * @param data 
 * @returns 
 */
export async function modifySysWarningRuleApi(data: ModifySysWarningRuleProps) {
    return request(`${api}/adq/sysWarningRule/configRuleAdgroupBatch`, {
        method: 'POST',
        data
    })
}

export interface GetAdWarningLogAdProps {
    pageNum: number,
    pageSize: number,
    adgroupId: string,
    accountId: string
    ruleId?: string
    operationType?: number
}
/**
 * 告警日志（按广告获取）
 * @param data 
 * @returns 
 */
export async function getAdWarningLogAdListApi(data: GetAdWarningLogAdProps) {
    return request(`${api}/tencentMonitor/adWarningLog/listByAd`, {
        method: 'POST',
        data
    })
}


export interface GetAdWarningLogRuleProps {
    pageNum: number,
    pageSize: number,
    ruleId: number
    adgroupId?: string,
    accountId?: string
    operationType?: number
}
/**
 * 告警日志（通过规则获取）
 * @param data 
 * @returns 
 */
export async function getAdWarningLogRuleListApi(data: GetAdWarningLogRuleProps) {
    return request(`${api}/tencentMonitor/adWarningLog/listByRule`, {
        method: 'POST',
        data
    })
}