/**
 * @desc 增加/编辑物料
 */
import { defaultSuccess, defaultError, http } from '@/plugins/axios'
import type { AxiosResponse } from 'axios'
export default async function (
	/** 请求体 */
	requestBody: material.Material,

	success: (data: material.Material) => void = defaultSuccess,
	fail: (error: { code: string; error?: string }) => void = defaultError,
): Promise<void> {
	return http({
		method: 'put',
		url: `/material`,
		data: requestBody,
	})
		.then((data: AxiosResponse<material.Material, unknown>) => {
			success(data.data)
		})
		.catch((error: { code: string; error?: string }) => fail(error))
}
