import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { StatementInvoiceVO, StatementInvoiceForm, StatementInvoiceQuery } from '@/api/bill/statementInvoice/types';

/**
 * 查询销售发票主列表
 * @param query
 * @returns {*}
 */

export const listStatementInvoice = (query?: StatementInvoiceQuery): AxiosPromise<StatementInvoiceVO[]> => {
  return request({
    url: '/bill/statementInvoice/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询销售发票主详细
 * @param id
 */
export const getStatementInvoice = (id: string | number): AxiosPromise<StatementInvoiceVO> => {
  return request({
    url: '/bill/statementInvoice/' + id,
    method: 'get'
  });
};

/**
 * 新增销售发票主
 * @param data
 */
export const addStatementInvoice = (data: StatementInvoiceForm) => {
  return request({
    url: '/bill/statementInvoice',
    method: 'post',
    data: data
  });
};

/**
 * 修改销售发票主
 * @param data
 */
export const updateStatementInvoice = (data: StatementInvoiceForm) => {
  return request({
    url: '/bill/statementInvoice',
    method: 'put',
    data: data
  });
};

/**
 * 删除销售发票主
 * @param id
 */
export const delStatementInvoice = (id: string | number | Array<string | number>) => {
  return request({
    url: '/bill/statementInvoice/' + id,
    method: 'delete'
  });
};

export function changeStatus(id: string | number, invoiceStatus: string) {
  const data = {
    id,
    invoiceStatus
  };
  return request({
    url: '/bill/statementInvoice/changeStatus',
    method: 'put',
    data: data
  });
}
