import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { BulletinVO, BulletinForm, BulletinQuery } from '@/api/system/bulletin/types';

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

export const listBulletin = (query?: BulletinQuery) => {
  return request({
    url: '/bulletin/list',
    method: 'post',
    data: query
  });
};

/**
 * 查询公告主详细
 * @param id
 */
export const getBulletin = (id: string | number, userId?: string | number): AxiosPromise<BulletinVO> => {
  return request({
    url: '/bulletin/get-by-id',
    method: 'post',
    data: { id, userId }
  });
};

/**
 * 新增公告主
 * @param data
 */
export const addBulletin = (data: BulletinForm) => {
  return request({
    url: '/bulletin/add',
    method: 'post',
    data: data
  });
};

/**
 * 修改公告主
 * @param data
 */
export const updateBulletin = (data: BulletinForm) => {
  return request({
    url: '/bulletin/edit',
    method: 'PUT',
    data,
  })
};

/**
 * 删除公告主
 * @param id
 */
export const delBulletin = (id: string | number | Array<string | number>) => {
  return request({
    url: `/bulletin/delete?id=` + id,
    method: 'delete',
  })
};

/**
 * 一键已读
 * @param id
 */
export const readAll = () => {
  return request({
    url: `/bulletin/is-read`,
    method: 'post',
  })
};
