import request from '@/utils/request'
import type { ApiResult, PageResult } from '@/api'
import type { ShopSigninRecord, ShopSigninRecordParam } from './model'

/**
 * 分页查询签到记录表
 */
export async function pageShopSigninRecord(params: ShopSigninRecordParam) {
  const res = await request.get<ApiResult<PageResult<ShopSigninRecord>>>(
    '/shop/shop-signin-record/page',
    params
  )
  if (res.code === 0) {
    return res.data
  }
  return Promise.reject(new Error(res.message))
}

/**
 * 查询签到记录表列表
 */
export async function listShopSigninRecord(params?: ShopSigninRecordParam) {
  const res = await request.get<ApiResult<ShopSigninRecord[]>>(
    '/shop/shop-signin-record',
    params
  )
  if (res.code === 0 && res.data) {
    return res.data
  }
  return Promise.reject(new Error(res.message))
}

/**
 * 添加签到记录表
 */
export async function addShopSigninRecord(data: Partial<ShopSigninRecord>) {
  const res = await request.post<ApiResult<unknown>>(
    '/shop/shop-signin-record',
    data
  )
  if (res.code === 0) {
    return res.message
  }
  return Promise.reject(new Error(res.message))
}

/**
 * 删除签到记录表
 */
export async function removeShopSigninRecord(id?: number) {
  const res = await request.del<ApiResult<unknown>>(
    '/shop/shop-signin-record/' + id
  )
  if (res.code === 0) {
    return res.message
  }
  return Promise.reject(new Error(res.message))
}
