import { http } from '@/utils/http/axios';
import { WorkShopTempleteType } from './secene-templet';

// 传入参数类型    还缺个场景list
export interface ComAddDatas {
  code?: string; //公司编码
  createdAt?: string; //创建时间
  id?: number; //新增后返回的唯一com的id
  isDeleted?: number; //是否删除
  name: string; //公司名字
  parentId?: number; //上级公司id  无上级为0
  remark?: string; //描述
  status?: number; //状态  0-启动  1-禁用
  updatedAt?: string;
  serial?: number; //排序
  labelList?: string[]; //创建的多个场景标签   自定义后面需要修改 这里没
  parent?: null | ComAddDatas;
  longitude?: number; //经度
  latitude?: number; //纬度
  regionCode: string;
}

/**
 * @description: 添加公司
 */
export const addCompany = (data: ComAddDatas): Promise<number> => {
  return http.request({
    url: '/scene/saveCompany',
    method: 'post',
    data,
  });
};

/**
 * @description: 编辑公司
 */
export const editCompany = (data: ComAddDatas): Promise<number> => {
  return http.request({
    url: '/scene/updateCompany',
    method: 'put',
    data,
  });
};

/**
 * @description: 删除公司
 */
export const delCompany = (companyId: number) => {
  return http.request({
    url: `/scene/deleteCompany?companyId=${companyId}`,
    method: 'DELETE',
  });
};

// 传入参数类型
export interface WorkshopAddDatas {
  code?: string;
  companyId?: number; //公司id
  sceneLabelId?: number; //类型  1-车间  2-危险点  3-物流  4-生活园区
  createdAt?: string;
  id?: number;
  isDeleted?: number;
  name: string;
  remark?: string;
  status?: number;
  updatedAt?: string;
  serial?: number;
  parent?: null | WorkshopAddDatas;
  workshopModule?: WorkShopTempleteType;
  labelList?: WorkShopTempleteType[];
  longitude?: number; //经度
  latitude?: number; //纬度
  // templete?: string; //车间模板
  // tag?: string; //场景标签
}

/**
 * @description: 添加车间
 */
export const addWorkshop = (data: WorkshopAddDatas): Promise<number> => {
  return http.request({
    url: '/scene/saveWorkshop',
    method: 'post',
    data,
  });
};

/**
 * @description: 编辑车间
 */
export const editWorkshop = (data: WorkshopAddDatas): Promise<number> => {
  return http.request({
    url: '/scene/updateWorkshop',
    method: 'put',
    data,
  });
};

/**
 * @description: 删除车间
 */
export const delWorkshop = (workshopId: number) => {
  return http.request({
    url: `/scene/deleteWorkshop?workshopId=${workshopId}`,
    method: 'DELETE',
  });
};

// 传入参数类型
export interface WorkspaceAddDatas {
  code?: string;
  createdAt?: string;
  id?: number;
  isDeleted?: number;
  name: string;
  principal?: string; //工位负责人
  remark?: string;
  status?: number;
  serial?: number;
  updatedAt?: string;
  workshopId?: number; //车间id
  parent?: null | WorkspaceAddDatas;
  longitude?: number; //经度
  latitude?: number; //纬度
  // tag?: string; //场景标签
}

/**
 * @description: 添加工位
 */
export const addWorkspace = (data: WorkspaceAddDatas): Promise<number> => {
  return http.request({
    url: '/scene/saveWorkspace',
    method: 'post',
    data,
  });
};

/**
 * @description: 编辑工位
 */
export const editWorkspace = (data: WorkspaceAddDatas): Promise<number> => {
  return http.request({
    url: '/scene/updateWorkspace',
    method: 'put',
    data,
  });
};

/**
 * @description: 删除工位
 */
export const delWorkspace = (workspaceId: number) => {
  return http.request({
    url: `/scene/deleteWorkspace?workspaceId=${workspaceId}`,
    method: 'DELETE',
  });
};

//获取列表
// 传入参数类型
export interface SceneListType<T, S> {
  code?: string;
  createdAt?: string;
  id?: number;
  isDeleted?: number;
  name?: string;
  parentId?: number;
  remark?: string;
  status?: number;
  serial?: number;
  updatedAt?: string;
  children?: T[]; //车间-工位信息
  labelList?: S[]; //创建的多个场景标签
  moduleList?: S[]; //创建得多个模板
}

export interface LabelModuleListType {
  code?: string;
  createdAt?: string;
  id?: number;
  isDeleted?: number;
  name?: string;
  remark?: string;
  status?: number;
  updatedAt?: string;
}

export interface GetListWorkshop<U, A> {
  code?: string;
  companyId?: number; //公司id
  sceneLabelId?: number; //类型  1-车间  2-危险点  3-物流  4-生活园区
  labelName?: string;
  createdAt?: string;
  id?: number;
  isDeleted?: number;
  name?: string;
  remark?: string;
  serial?: number;
  status?: number;
  updatedAt?: string;
  children?: U[]; //工位信息
  workshopModule?: A; //车间模板
  // tag?: string; //场景标签  自定义  后面需要修改
}

export const getSceneList = (): Promise<
  SceneListType<GetListWorkshop<WorkspaceAddDatas, WorkShopTempleteType>, LabelModuleListType>[]
> => {
  return http.request({
    url: '/scene/getList',
    method: 'get',
  });
};

//排序列表
export const sortSceneList = (
  data: SceneListType<
    GetListWorkshop<WorkspaceAddDatas, WorkShopTempleteType>,
    LabelModuleListType
  >[],
) => {
  return http.request({
    url: '/scene/updateSort',
    method: 'put',
    data,
  });
};
