import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CodeRuleVO, CodeRuleForm, CodeRuleQuery } from '@/api/system/codeRule/types';

/**
 * 查询编码规则列表
 * @param query
 * @returns {*}
 */
export const listCodeRule = (query?: CodeRuleQuery): AxiosPromise<CodeRuleVO[]> => {
  return request({
    url: '/system/codeRule/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询编码规则详细
 * @param codeRuleId
 */
export const getCodeRule = (codeRuleId: string | number): AxiosPromise<CodeRuleVO> => {
  return request({
    url: '/system/codeRule/' + codeRuleId,
    method: 'get'
  });
};

/**
 * 新增编码规则
 * @param data
 */
export const addCodeRule = (data: CodeRuleForm) => {
  return request({
    url: '/system/codeRule',
    method: 'post',
    data: data
  });
};

/**
 * 修改编码规则
 * @param data
 */
export const updateCodeRule = (data: CodeRuleForm) => {
  return request({
    url: '/system/codeRule',
    method: 'put',
    data: data
  });
};

/**
 * 删除编码规则
 * @param codeRuleId
 */
export const delCodeRule = (codeRuleId: string | number | Array<string | number>) => {
  return request({
    url: '/system/codeRule/' + codeRuleId,
    method: 'delete'
  });
};


/**
 * 下拉框查询编码规则列表
 * @param query
 * @returns {*}
 */
export function getSysCodeRuleList(query) {
  return request({
    url: '/system/codeRule/getSysCodeRuleList',
    method: 'get',
    params: query
  });
};

/**
 * 查询编码规则列表
 * @param query
 * @returns {*}
 */
export const getRuleGenerateCode = (query: CodeRuleForm) => {
  return request({
    url: '/system/codeRule/getRuleGenerateCode',
    method: 'get',
    params: query
  });
};
