/**
 * @desc 增加/编辑码本数据
 */
import { defaultSuccess, defaultError, http } from '@/plugins/axios';
import type { AxiosResponse } from 'axios';
export default async function (
  /** 码本分组key */
  group: string,

  /** 请求体 */
  requestBody: dictionary.Dictionary,

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