import request from '@/utils/request';
import { OrgConfigForm, OrgConfigQuery } from './types';

// 查询配置列表
export function listOrgConfig(query: OrgConfigQuery) {
  return request({
    url: '/system/orgConfig/list',
    method: 'get',
    params: query
  });
}

// 获取配置详细信息
export function getOrgConfig(configCode: string) {
  return request({
    url: '/system/orgConfig/' + configCode,
    method: 'get'
  });
}

// 新增配置
export function addOrgConfig(data: OrgConfigForm) {
  return request({
    url: '/system/orgConfig',
    method: 'post',
    data: data
  });
}

// 修改配置
export function updateOrgConfig(data: OrgConfigForm) {
  return request({
    url: '/system/orgConfig',
    method: 'put',
    data: data
  });
}

// 删除配置
export function delOrgConfig(configCode: string | Array<string>) {
  return request({
    url: '/system/orgConfig/' + configCode,
    method: 'delete'
  });
}

// 获取序列类型
export function getSeriesTypes(branchType?: string) {
  return request({
    url: '/system/orgConfig/seriesTypes',
    method: 'get',
    params: { branchType }
  });
}

// ==================== 层级管理 ====================

// 查询层级列表
export function listOrgLevelDefs(query: any) {
  return request({
    url: '/system/orgConfig/levels/list',
    method: 'get',
    params: query
  });
}

// 获取层级详情
export function getOrgLevelDefs(configCode: string) {
  return request({
    url: '/system/orgConfig/levels/' + configCode,
    method: 'get'
  });
}

// 新增层级
export function addOrgLevelDef(data: any) {
  return request({
    url: '/system/orgConfig/levels',
    method: 'post',
    data: data
  });
}

// 修改层级
export function updateOrgLevelDef(data: any) {
  return request({
    url: '/system/orgConfig/levels',
    method: 'put',
    data: data
  });
}

// 删除层级
export function delOrgLevelDef(id: string | number) {
  return request({
    url: '/system/orgConfig/levels/' + id,
    method: 'delete'
  });
}

// 批量删除层级
export function batchDelOrgLevelDef(ids: Array<string | number>) {
  return request({
    url: '/system/orgConfig/levels/batch/' + ids.join(','),
    method: 'delete'
  });
}

// ==================== 职级管理 ====================

// 查询职级列表
export function listGradeDefs(query: any) {
  return request({
    url: '/system/orgConfig/grades/list',
    method: 'get',
    params: query
  });
}

// 获取职级详情
export function getGradeDefs(configCode: string) {
  return request({
    url: '/system/orgConfig/grades/' + configCode,
    method: 'get'
  });
}

// 新增职级
export function addGradeDef(data: any) {
  return request({
    url: '/system/orgConfig/grades',
    method: 'post',
    data: data
  });
}

// 修改职级
export function updateGradeDef(data: any) {
  return request({
    url: '/system/orgConfig/grades',
    method: 'put',
    data: data
  });
}

// 删除职级
export function delGradeDef(id: string | number) {
  return request({
    url: '/system/orgConfig/grades/' + id,
    method: 'delete'
  });
}

// 批量删除职级
export function batchDelGradeDef(ids: Array<string | number>) {
  return request({
    url: '/system/orgConfig/grades/batch/' + ids.join(','),
    method: 'delete'
  });
}

// 获取序列类型定义
export function getSeriesTypeDefs() {
  return request({
    url: '/system/orgConfig/seriesTypeDefs',
    method: 'get'
  });
}

// ==================== 自动创建规则 ====================

// 查询自动创建规则列表
export function listAutoCreateRules(query: any) {
  return request({
    url: '/system/orgConfig/autoRules/list',
    method: 'get',
    params: query
  });
}

// 获取自动创建规则
export function getAutoCreateRules(configCode: string) {
  return request({
    url: '/system/orgConfig/autoRules/' + configCode,
    method: 'get'
  });
}

// 新增自动创建规则
export function addAutoCreateRule(data: any) {
  return request({
    url: '/system/orgConfig/autoRules',
    method: 'post',
    data: data
  });
}

// 修改自动创建规则
export function updateAutoCreateRule(data: any) {
  return request({
    url: '/system/orgConfig/autoRules',
    method: 'put',
    data: data
  });
}

// 删除自动创建规则
export function delAutoCreateRule(id: string | number) {
  return request({
    url: '/system/orgConfig/autoRules/' + id,
    method: 'delete'
  });
}

// 批量删除自动创建规则
export function batchDelAutoCreateRule(ids: Array<string | number>) {
  return request({
    url: '/system/orgConfig/autoRules/batch/' + ids.join(','),
    method: 'delete'
  });
}

// ==================== 配置使用关系 ====================

// 查询配置使用列表
export function listConfigUsage(query: any) {
  return request({
    url: '/system/orgConfig/usage/list',
    method: 'get',
    params: query
  });
}

// 设置配置使用关系
export function setOrgConfigUsage(data: any) {
  return request({
    url: '/system/orgConfig/usage',
    method: 'post',
    data: data
  });
}

// 修改配置使用关系
export function updateOrgConfigUsage(data: any) {
  return request({
    url: '/system/orgConfig/usage',
    method: 'put',
    data: data
  });
}

// 删除配置使用关系
export function deleteOrgConfigUsage(id: string | number) {
  return request({
    url: '/system/orgConfig/usage/' + id,
    method: 'delete'
  });
}
