import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { EmployeeVO, EmployeeForm, EmployeeQuery } from '@/api/system/employee/types';

/**
 * 查询员工列表
 * @param query
 */
export const listEmployee = (query?: EmployeeQuery): AxiosPromise<EmployeeVO[]> => {
  return request({
    url: '/system/employee/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询员工详细
 * @param id
 */
export const getEmployee = (id: string | number): AxiosPromise<EmployeeVO> => {
  return request({
    url: '/system/employee/' + id,
    method: 'get'
  });
};

/**
 * 查询员工详情（含授权客户完整信息列表）
 * @param id
 */
export const getEmployeeDetail = (id: string | number): AxiosPromise<EmployeeVO> => {
  return request({
    url: '/system/employee/detail/' + id,
    method: 'get'
  });
};

/**
 * 新增员工
 * @param data
 */
export const addEmployee = (data: EmployeeForm) => {
  return request({
    url: '/system/employee',
    method: 'post',
    data: data
  });
};

/**
 * 授权客户（支持多个，逗号分隔）
 * @param id 员工ID
 * @param authClientFRowIDs 授权客户 RowID 列表（逗号分隔）
 */
export const authEmployee = (id: string | number, authClientFRowIDs: string) => {
  return request({
    url: '/system/employee/auth',
    method: 'put',
    params: { id, authClientFRowIDs }
  });
};

/**
 * 修改员工状态（启用/禁用）
 */
export const changeEmployeeStatus = (id: string | number, status: string) => {
  return request({
    url: '/system/employee/changeStatus',
    method: 'put',
    params: { id, status }
  });
};

/**
 * 导出员工列表
 * @param query
 */
export const exportEmployee = (query: EmployeeQuery) => {
  return request({
    url: '/system/employee/export',
    method: 'post',
    params: query,
    responseType: 'blob'
  });
};
