import { request } from 'umi';
import { ListData, SysAdgroupsDTO } from '.';
import { api } from '../api';

/**
 * 获取广告组列表
 * @param adgroupName 广告名称
 * @param promotedObjectType 广告类型
 */
export async function getSysAdgroupsList(params: {
  pageNum: number;
  pageSize: number;
  adgroupName?: string;
  promotedObjectType?: string;
}): Promise<ListData<SysAdgroupsDTO>> {
  return request(api + '/adq/sysAdgroups/list', {
    method: 'POST',
    data: params,
  })
}
/**
 * 获取广告详情
 * @param adgroupsId 广告ID
 */
export async function getSysAdgroupsInfo(adgroupsId: any) {
  return request(api + `/adq/sysAdgroups/${adgroupsId}`)
}
/**
 * 新增广告
 * */
export async function createSysAdgroups(params: SysAdgroupsDTO) {
  return request(api + `/adq/sysAdgroups`, {
    method: 'POST',
    data: params
  })
}
/**
 * 编辑广告
 * */
export async function editSysAdgroups(adgroupsId: string, params: SysAdgroupsDTO) {
  return request(api + `/adq/sysAdgroups/${adgroupsId}`, {
    method: 'PUT',
    data: params
  })
}
/**
 * 删除广告
 * */
export async function delSysAdgroups(adgroupsId: string) {
  return request(api + `/adq/sysAdgroups/${adgroupsId}`, {
    method: 'DELETE',
  })
}

export interface AddStrategyProps {
  promotedObjectType: string,
  strategyKey: string,
  strategyValue: string,
  remark?: string,
  strategyId?: number
}
/**
 * 新增策略组
 * @param data 
 * @returns 
 */
export async function addStrategyApi(data: AddStrategyProps) {
  return request(api + `/adq/strategy/add`, {
    method: 'POST',
    data
  })
}

/**
 * 策略组列表
 * @param params 
 * @returns 
 */
export async function getStrategyApi(params: { promotedObjectType?: string, strategyKey?: string }) {
  return request(api + `/adq/strategy/list`, {
    method: 'GET',
    params
  })
}

/**
 * 策略组删除
 * @param strategyId 
 * @returns 
 */
export async function delStrategyApi(strategyId: number) {
  return request(api + `/adq/strategy/delete/${strategyId}`, {
    method: 'POST'
  })
}