import { request } from '/@/utils/service';
import { AddReq, DelReq, EditReq, UserPageQuery } from '@fast-crud/fast-crud';

export const apiPrefix = '/api/ad_manage/auto_plan_template/';

export function GetList(query: UserPageQuery) {
  return request({
    url: apiPrefix,
    method: 'get',
    params: query,
  });
}

export function GetObj(id: number) {
  return request({
    url: apiPrefix + id,
    method: 'get',
  });
}

export function AddObj(obj: AddReq) {
  return request({
    url: apiPrefix,
    method: 'post',
    data: obj,
  });
}

export function UpdateObj(obj: EditReq) {
  return request({
    url: apiPrefix + obj.id + '/',
    method: 'put',
    data: obj,
  });
}

export function DelObj(id: DelReq) {
  return request({
    url: apiPrefix + id + '/',
    method: 'delete',
    data: { id },
  });
}

// 关联广告活动
export function getRelationCampaign(query) {
  return request({
    url: '/api/ad_manage/template/relation_campaign_list/',
    method: 'GET',
    params: query,
  });
}

// 广告组合下拉框
export function getAdGroupList(query) {
  return request({
    url: '/api/ad_manage/ad_tree/portfolios',
    method: 'GET',
    params: query,
  });
}

// 广告关联活动保存
export function updateAdCampaign(body) {
  return request({
    url: '/api/ad_manage/template/relation_campaign_enable/',
    method: 'POST',
    data: body,
  });
}

// 广告关联活动
export function getSelectedAdCampaign(query) {
  return request({
    url: '/api/ad_manage/template/selected-campaigns/',
    method: 'GET',
    params: query,
  });
}

// 定向规则弹窗：获取定向规则列表
export function getTargetingRuleList(query) {
  return request({
    url: '/api/ad_manage/template/target_select',
    method: 'GET',
    params: query,
  });
}

// 定向规则弹窗：获取商品列表
export function getProductsList(query) {
  return request({
    url: '/api/ad_manage/template/target_select/products/',
    method: 'GET',
    params: query,
  });
}




