import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { TemplateVariableVO, TemplateVariableForm, TemplateVariableQuery } from '@/api/oa/base/templateVariable/types';

/**
 * 查询模板变量信息列表
 * @param query
 * @returns {*}
 */

export const listTemplateVariable = (query?: TemplateVariableQuery): AxiosPromise<TemplateVariableVO[]> => {
  return request({
    url: '/oa/base/templateVariable/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询模板变量信息详细
 * @param variableId
 */
export const getTemplateVariable = (variableId: string | number): AxiosPromise<TemplateVariableVO> => {
  return request({
    url: '/oa/base/templateVariable/' + variableId,
    method: 'get'
  });
};

/**
 * 新增模板变量信息
 * @param data
 */
export const addTemplateVariable = (data: TemplateVariableForm) => {
  return request({
    url: '/oa/base/templateVariable',
    method: 'post',
    data: data
  });
};

/**
 * 修改模板变量信息
 * @param data
 */
export const updateTemplateVariable = (data: TemplateVariableForm) => {
  return request({
    url: '/oa/base/templateVariable',
    method: 'put',
    data: data
  });
};

/**
 * 删除模板变量信息
 * @param variableId
 */
export const delTemplateVariable = (variableId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/base/templateVariable/' + variableId,
    method: 'delete'
  });
};

/**
 * 下拉框查询模板变量信息列表
 * @param query
 * @returns {*}
 */
export function getBaseTemplateVariableList (query) {
    return request({
        url: '/oa/base/templateVariable/getBaseTemplateVariableList',
        method: 'get',
        params: query
    });
};

export function templateAssign(query) {
  return request({
    url: '/oa/base/templateVariable/assign',
    method: 'post',
    data: query
  });
};
