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

/**
 * 分页查询活动报名表
 */
export async function pageShopActivitySignup(params: ShopActivitySignupParam) {
  const res = await request.get<ApiResult<PageResult<ShopActivitySignup>>>(
    '/shop/shop-activity-signup/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询活动报名表列表
 */
export async function listShopActivitySignup(params?: ShopActivitySignupParam) {
  const res = await request.get<ApiResult<ShopActivitySignup[]>>(
    '/shop/shop-activity-signup',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加活动报名表
 */
export async function addShopActivitySignup(data: ShopActivitySignup) {
  const res = await request.post<ApiResult<unknown>>(
    '/shop/shop-activity-signup',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改活动报名表
 */
export async function updateShopActivitySignup(data: ShopActivitySignup) {
  const res = await request.put<ApiResult<unknown>>(
    '/shop/shop-activity-signup',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除活动报名表
 */
export async function removeShopActivitySignup(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    '/shop/shop-activity-signup/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除活动报名表
 */
export async function removeBatchShopActivitySignup(data: (number | undefined)[]) {
  const res = await request.delete<ApiResult<unknown>>(
    '/shop/shop-activity-signup/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询活动报名表
 */
export async function getShopActivitySignup(id: number) {
  const res = await request.get<ApiResult<ShopActivitySignup>>(
    '/shop/shop-activity-signup/' + id
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
