import { axiosClient } from '@/api/axiosClient'
import type { ChargeableCharConfig, ChargeableCharConfigsQuery, PagedResult } from '../types'

export async function listChargeableCharConfigs(
  query: ChargeableCharConfigsQuery,
): Promise<PagedResult<ChargeableCharConfig>> {
  const params = new URLSearchParams()
  if (query.productTypeId !== undefined) params.set('productTypeId', String(query.productTypeId))
  if (query.activeOnly !== undefined) params.set('activeOnly', String(query.activeOnly))
  if (query.page !== undefined) params.set('page', String(query.page))
  if (query.pageSize !== undefined) params.set('pageSize', String(query.pageSize))

  const response = await axiosClient.get<PagedResult<ChargeableCharConfig>>(
    '/api/v1/admin/chargeable-chars',
    { params },
  )
  return response.data
}
