import { http } from '@/utils/http/axios';
import type { QueryPageRequest, QueryPageResponse } from '@/types/basic-query';
import {
  ApprovalInstanceType,
  ApprovalInstanceRuleForm,
  ApprovalNodeInstanceRuleForm,
} from '@/views/system/approval/types';

export function getApprovalInstanceList(query: QueryPageRequest<any>) {
  return http.request<QueryPageResponse<any>>({
    url: '/approvalManagement/queryApprovalTemplatePage',
    method: 'post',
    data: query,
  });
}

export function getApprovalNodeInstanceList(id: number) {
  return http.request<ApprovalInstanceType>({
    url: `/approvalManagement/queryApprovalTemplateDetail?approvalTemplateId=${id}`,
    method: 'get',
  });
}

export function addApprovalInstance(params: ApprovalInstanceRuleForm) {
  return http.request({
    url: '/approvalManagement/saveOrUpdateApprovalTemplate',
    method: 'post',
    data: params,
  });
}

export function updateApprovalInstance(params: ApprovalInstanceRuleForm) {
  return addApprovalInstance(params);
}

export function delApprovalInstance(id: number) {
  return http.request({
    url: `/approvalManagement/deleteApprovalTemplate?id=${id}`,
    method: 'delete',
  });
}

export function addApprovalNodeInstance(params: ApprovalNodeInstanceRuleForm) {
  return http.request({
    url: '/approvalManagement/saveOrUpdateApprovalNode',
    method: 'post',
    data: params,
  });
}

export function updateApprovalNodeInstance(params: ApprovalNodeInstanceRuleForm) {
  return addApprovalNodeInstance(params);
}

export function updateApprvoerInfo(params: ApprovalNodeInstanceRuleForm) {
  return addApprovalNodeInstance(params);
}

export function delApprovalNodeInstance(id: number) {
  return http.request({
    url: `/approvalManagement/deleteApprovalNode?approvalTemplateDetailId=${id}`,
    method: 'delete',
  });
}

export function getAllApproval() {
  return http.request<ApprovalInstanceType[]>({
    url: '/approvalManagement/queryAllApprovalTemplate',
    method: 'get',
  });
}
