import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { AdVO, AdForm, AdQuery } from '@/api/dgtmedicine/ad/types';

/**
 * 查询广告列表
 * @param query
 * @returns {*}
 */

export const listAd = (query?: AdQuery): AxiosPromise<AdVO[]> => {
  return request({
    url: '/dgtmedicine/ad/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询广告详细
 * @param id
 */
export const getAd = (id: string | number): AxiosPromise<AdVO> => {
  return request({
    url: '/dgtmedicine/ad/getInfo/' + id,
    method: 'get'
  });
};

/**
 * 新增广告
 * @param data
 */
export const addAd = (data: AdForm) => {
  return request({
    url: '/dgtmedicine/ad/add',
    method: 'post',
    data: data
  });
};

/**
 * 修改广告
 * @param data
 */
export const updateAd = (data: AdForm) => {
  return request({
    url: '/dgtmedicine/ad/edit',
    method: 'post',
    data: data
  });
};

/**
 * 删除广告
 * @param id
 */
export const delAd = (id: string | number | Array<string | number>) => {
  return request({
    url: '/dgtmedicine/ad/remove/' + id,
    method: 'get'
  });
};


/**
 * 上架广告
 * @param id
 */
export const publishAd = (id: string | number) => {
  return request({
    url: '/dgtmedicine/ad/publish/' + id,
    method: 'get'
  });
};

/**
 * 下架广告
 * @param id
 */
export const unpublishAd = (id: string | number) => {
  return request({
    url: '/dgtmedicine/ad/unpublish/' + id,
    method: 'get'
  });
};