import { request } from '../../utils/axios';

export interface FormVO {
  id?: number;
  name: string;
  conf: string;
  fields: string[];
  status: number;
  remark?: string;
  createTime?: string;
}

export interface FormPageParams {
  pageNo: number;
  pageSize: number;
  name?: string;
  status?: number;
}

export interface FormPageResponse {
  list: FormVO[];
  total: number;
}

// 创建工作流的表单定义
export const createForm = async (data: FormVO): Promise<void> => {
  await request.post({
    url: '/bpm/form/create',
    data: data
  });
};

// 更新工作流的表单定义
export const updateForm = async (data: FormVO): Promise<void> => {
  await request.put({
    url: '/bpm/form/update',
    data: data
  });
};

// 删除工作流的表单定义
export const deleteForm = async (id: number): Promise<void> => {
  await request.delete({
    url: `/bpm/form/delete?id=${id}`
  });
};

// 获得工作流的表单定义
export const getForm = async (id: number): Promise<FormVO> => {
  const response = await request.get({
    url: `/bpm/form/get?id=${id}`
  });
  return response as FormVO;
};

// 获得工作流的表单定义分页
export const getFormPage = async (params: FormPageParams): Promise<FormPageResponse> => {
  const response = await request.get({
    url: '/bpm/form/page',
    params
  });
  return response as FormPageResponse;
};

// 获得动态表单的 精简列表
export const getFormSimpleList = async (): Promise<FormVO[]> => {
  const response = await request.get({    
    url: '/bpm/form/simple-list'
  });
  return response as FormVO[];
};

// 更新表单状态
export interface UpdateFormStatusParams {
  id: number;
  status: number; // 0-开启，1-关闭
}

export const updateFormStatus = async (params: UpdateFormStatusParams): Promise<void> => {
  await request.put({
    url: '/bpm/form/updateStatus',
    data: params
  });
};

