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

/**
 * 分页查询水票释放
 */
export async function pageGltUserTicketRelease(params: GltUserTicketReleaseParam) {
  const res = await request.get<ApiResult<PageResult<GltUserTicketRelease>>>(
    '/glt/glt-user-ticket-release/page',
    {
      params
    }
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 查询水票释放列表
 */
export async function listGltUserTicketRelease(params?: GltUserTicketReleaseParam) {
  const res = await request.get<ApiResult<GltUserTicketRelease[]>>(
    '/glt/glt-user-ticket-release',
    {
      params
    }
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 添加水票释放
 */
export async function addGltUserTicketRelease(data: GltUserTicketRelease) {
  const res = await request.post<ApiResult<unknown>>(
    '/glt/glt-user-ticket-release',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 修改水票释放
 */
export async function updateGltUserTicketRelease(data: GltUserTicketRelease) {
  const res = await request.put<ApiResult<unknown>>(
    '/glt/glt-user-ticket-release',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 删除水票释放
 */
export async function removeGltUserTicketRelease(id?: number) {
  const res = await request.del<ApiResult<unknown>>(
    '/glt/glt-user-ticket-release/' + id
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 批量删除水票释放
 */
export async function removeBatchGltUserTicketRelease(data: (number | undefined)[]) {
  const res = await request.del<ApiResult<unknown>>(
    '/glt/glt-user-ticket-release/batch',
    {
      data
    }
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据id查询水票释放
 */
export async function getGltUserTicketRelease(id: number) {
  const res = await request.get<ApiResult<GltUserTicketRelease>>(
    '/glt/glt-user-ticket-release/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
