/* eslint-disable @typescript-eslint/member-ordering */
import { get, post } from '../request'
import type { PageResponse } from '../request'

export abstract class BasicService<T> {
  protected abstract findPageUrl(): string
  protected abstract saveOrUpdateUrl(): string
  protected abstract removeUrl(): string
  // 增/改（自动根据id判断）
  async saveOrUpdate(entity: T) {
    return await post(this.saveOrUpdateUrl(), entity)
  }

  // id、id[]
  async remove(ids: any): Promise<any> {
    if (!Array.isArray(ids)) {
      ids = [ids]
    }
    return await post(this.removeUrl(), ids)
  }

  // 分页查询
  async findPage<T>(current: number, size: number, condition: any): Promise<PageResponse<T>> {
    return await get<PageResponse<T>>(this.findPageUrl(), {
      size,
      current,
      ...(condition || {}),
    })
  }
}
