import { request } from '/@/utils/service';
import { UserPageQuery, AddReq, EditReq, InfoReq } from '@fast-crud/fast-crud';
import { Session } from '/@/utils/storage';

export interface OrganizationParams {
  name: string;
  code: string;
  org_type: 1 | 2 | 3 | 4; // 1=学院，2=系部，3=年级，4=班级/组别
  parent: number | null;
  sort: number;
  description: string;
  is_active: boolean;
}

export const ORG_TYPE_OPTIONS = [
  { value: 1, label: '学校' },
  { value: 2, label: '院系' },
  { value: 3, label: '专业' },
  { value: 4, label: '班级' },
];

/* 获取设备列表 */
export function GetEquipList(query: any) {
  return request({
    url: '/api/system/organization/tree/',
    method: 'get',
    params: {...query,merchant:Session.get('merchant_info').merchant_id},
  });
}

/* 获取分类 */
export function GetCategoryList(query: any) {
  return request({
    url: '/api/system/component-categories/',
    method: 'get',
    params: {...query,merchant:Session.get('merchant_info').merchant_id},
  });
}

/* 新增分类 */
export function AddCategory(query: any) {
  return request({
    url: '/api/system/component-categories/',
    method: 'post',
    data: {...query,merchant:Session.get('merchant_info').merchant_id},
  });
}

/* 编辑分类 */
export function EditCategory(query: any) {
  return request({
    url: '/api/system/component-categories/' + query.id + '/',
    method: 'put',
    data: {...query,merchant:Session.get('merchant_info').merchant_id},
  });
}

/* 删除分类 */
export function DeleteCategory(query: any) {
  return request({
    url: '/api/system/component-categories/' + query.id + '/',
    method: 'delete',
    data: {...query,merchant:Session.get('merchant_info').merchant_id},
  });
}

export function GetFactoryList(query: UserPageQuery) {
  return request({
    url: '/api/system/paper-machine-types/',
    method: 'get',
    params: {...query,merchant:Session.get('merchant_info').merchant_id},
  });
}


/* 新增设备 */
export function AddEquipment(query: any) {
  return request({
    url: '/api/system/component/',
    method: 'post',
    data: {...query,merchant:Session.get('merchant_info').merchant_id},
  });
}


/* 编辑设备 */
export function EditEquipment(query: any) {
  return request({
    url: '/api/system/component/' + query.id + '/',
    method: 'put',
    data: {...query,merchant:Session.get('merchant_info').merchant_id},
  });
}

/* 删除设备 */
export function DeleteEquipment(query: any) {
  return request({
    url: '/api/system/component/' + query.id + '/',
    method: 'delete',
    data: {...query,merchant:Session.get('merchant_info').merchant_id},
  });
}

/* 获取设备详情 */
export function GetEquipmentDetail(query: any) {
  return request({
    url: '/api/system/component/' + query.id + '/',
    method: 'get',
    data: {...query,merchant:Session.get('merchant_info').merchant_id},
  });
}

/* 获取设备列表 */
export function GetEquipmentList(query: any) {
  return request({
    url: '/api/system/component/',
    method: 'get',
    params: {...query,merchant:Session.get('merchant_info').merchant_id},
  });
}
  
/* 获取设备文档列表 */
export function GetEquipmentDocuments(query: any) {
  return request({
    url: '/api/system/document/',
    method: 'get',
    params: {...query,merchant:Session.get('merchant_info').merchant_id},
  });
}

/* 获取组织机构树 */
export function GetOrganizationTree() {
  return request({
    url: '/api/system/organization/tree/',
    method: 'get',
    /* params: {merchant:Session.get('merchant_info').merchant_id}, */
  });
}

/* 创建组织机构 */
export function CreateOrganization(data: OrganizationParams) {
  return request({
    url: '/api/system/organization/',
    method: 'post',
    data: {...data},
  });
}

/* 更新组织机构 */
export function UpdateOrganization(id: number, data: OrganizationParams) {
  return request({
    url: `/api/system/organization/${id}/`,
    method: 'put',
    data: {...data},
  });
}

/* 删除组织机构 */
export function DeleteOrganization(id: number) {
  return request({
    url: `/api/system/organization/${id}/`,
    method: 'delete',
  /*   data: {merchant:Session.get('merchant_info').merchant_id}, */
  });
}
