import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { ThinkAdminLog, ThinkAdminLogParam } from './model';
import { THINK_API_URL } from '@/config/setting';

/**
 * 分页查询后台金额操作变动
 */
export async function pageThinkAdminLog(params: ThinkAdminLogParam) {
  const res = await request.get<ApiResult<PageResult<ThinkAdminLog>>>(
    THINK_API_URL + '/think/think-admin-log/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询后台金额操作变动列表
 */
export async function listThinkAdminLog(params?: ThinkAdminLogParam) {
  const res = await request.get<ApiResult<ThinkAdminLog[]>>(
    THINK_API_URL + '/think/think-admin-log',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加后台金额操作变动
 */
export async function addThinkAdminLog(data: ThinkAdminLog) {
  const res = await request.post<ApiResult<unknown>>(
    THINK_API_URL + '/think/think-admin-log',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改后台金额操作变动
 */
export async function updateThinkAdminLog(data: ThinkAdminLog) {
  const res = await request.put<ApiResult<unknown>>(
    THINK_API_URL + '/think/think-admin-log',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除后台金额操作变动
 */
export async function removeThinkAdminLog(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    THINK_API_URL + '/think/think-admin-log/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除后台金额操作变动
 */
export async function removeBatchThinkAdminLog(data: (number | undefined)[]) {
  const res = await request.delete<ApiResult<unknown>>(
    THINK_API_URL + '/think/think-admin-log/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询后台金额操作变动
 */
export async function getThinkAdminLog(id: number) {
  const res = await request.get<ApiResult<ThinkAdminLog>>(
    THINK_API_URL + '/think/think-admin-log/' + id
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
