import { request } from "./client";

export interface ModuleTreeVO {
  iIncrement: number;
  sModuleNameZh: string;
  sDisplayType: string;
  sManageDeptEn: string;
  iParentId: number | null;
  iSortOrder: number;
  children: ModuleTreeVO[];
}

export interface ModuleDTO {
  sDisplayType: string;
  sProcedureName?: string;
  sModuleType: string;
  sManageDeptEn: string;
  bShowPermission?: boolean;
  sModuleNameZh: string;
  iParentId?: number | null;
  iSortOrder?: number;
}

export function listModules(keyword?: string): Promise<ModuleTreeVO[]> {
  return request<ModuleTreeVO[]>({
    url: "/mod/modules",
    method: "GET",
    params: keyword ? { keyword } : {},
  });
}

export function createModule(dto: ModuleDTO): Promise<{ iIncrement: number }> {
  return request({ url: "/mod/modules", method: "POST", data: dto });
}

export function updateModule(
  id: number,
  dto: ModuleDTO
): Promise<{ iIncrement: number }> {
  return request({ url: `/mod/modules/${id}`, method: "PUT", data: dto });
}

export function deleteModule(id: number): Promise<void> {
  return request({ url: `/mod/modules/${id}`, method: "DELETE" });
}
