import request from "@/utils/request";

/*************************************************
 ****************** 组织机构相关接口 ******************
 *************************************************/

/**
 * 获取组织机构列表
 * @returns {Promise}
 */
export function getOrganizationList() {
  return request({
    url: '/platform/erp/getOrganization',
    method: 'get'
  });
}

/**
 * 获取组织机构详情
 * @param {number} id 组织机构ID
 * @returns {Promise}
 */
export function getOrganizationDetail(id) {
  return request({
    url: `/platform/erp/getOrganizationDetail/${id}`,
    method: "get",
  });
}

/**
 * 创建组织机构数据
 * @param {Object} data 组织机构数据
 * @returns {Promise}
 */
export function createOrganization(data) {
  return request({
    url: "/platform/erp/createOrganization",
    method: "post",
    data: data,
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
}

// 更新组织机构信息
export function editOrganization(id, data) {
  return request({
    url: `/platform/erp/editOrganization/${id}`,
    method: 'post',
    data: data
  });
}

/**
 * 删除组织机构数据
 * @param {number} id 组织机构ID
 * @returns {Promise}
 */
export function deleteOrganization(id) {
  return request({
    url: `/platform/erp/deleteOrganization/${id}`,
    method: "delete",
  });
}

/**
 * 获取企业单位列表
 * @returns {Promise}
 */
export function getCompanys() {
  return request({
    url: '/platform/erp/getCompanys',
    method: 'get'
  });
}

/**
 * 获取部门列表
 * @param {number} parentId 隶属单位ID
 * @returns {Promise}
 */
export function getDepartments(parentId) {
  return request({
    url: '/platform/erp/getDepartments',
    method: 'get',
    params: parentId ? { parent_id: parentId } : {}
  });
}

/*************************************************
 ****************** 员工相关接口 ******************
 *************************************************/

/**
 * 获取员工列表
 * @param {number} tenantId 租户ID
 * @returns {Promise}
 */
export function getEmployeeList(tenantId) {
  return request({
    url: '/platform/erp/getEmployee',
    method: 'get',
    params: { tid: tenantId }
  });
}

/**
 * 获取员工详情
 * @param {number} id 员工ID
 * @returns {Promise}
 */
export function getEmployeeDetail(id) {
  return request({
    url: `/platform/erp/getEmployeeDetail/${id}`,
    method: "get",
  });
}

/**
 * 创建员工数据
 * @param {Object} data 员工数据
 * @returns {Promise}
 */
export function createEmployee(data) {
  return request({
    url: "/platform/erp/createEmployee",
    method: "post",
    data: data,
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
}

// 更新员工信息
export function editEmployee(id, data) {
  return request({
    url: `/platform/erp/editEmployee/${id}`,
    method: 'post',
    data: data
  });
}

/**
 * 删除员工数据
 * @param {number} id 员工ID
 * @returns {Promise}
 */
export function deleteEmployee(id) {
  return request({
    url: `/platform/erp/deleteEmployee/${id}`,
    method: "delete",
  });
}
