import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { GltUserTicketLog, GltUserTicketLogParam } from './model';

/**
 * 分页查询消费日志
 */
export async function pageGltUserTicketLog(params: GltUserTicketLogParam) {
  const res = await request.get<ApiResult<PageResult<GltUserTicketLog>>>(
    '/glt/glt-user-ticket-log/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询消费日志列表
 */
export async function listGltUserTicketLog(params?: GltUserTicketLogParam) {
  const res = await request.get<ApiResult<GltUserTicketLog[]>>(
    '/glt/glt-user-ticket-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 addGltUserTicketLog(data: GltUserTicketLog) {
  const res = await request.post<ApiResult<unknown>>(
    '/glt/glt-user-ticket-log',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改消费日志
 */
export async function updateGltUserTicketLog(data: GltUserTicketLog) {
  const res = await request.put<ApiResult<unknown>>(
    '/glt/glt-user-ticket-log',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除消费日志
 */
export async function removeGltUserTicketLog(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    '/glt/glt-user-ticket-log/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除消费日志
 */
export async function removeBatchGltUserTicketLog(data: (number | undefined)[]) {
  const res = await request.delete<ApiResult<unknown>>(
    '/glt/glt-user-ticket-log/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询消费日志
 */
export async function getGltUserTicketLog(id: number) {
  const res = await request.get<ApiResult<GltUserTicketLog>>(
    '/glt/glt-user-ticket-log/' + id
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
