import { axiosClient } from '@/api/axiosClient'
import type { MedioListItem, MediosQuery, PagedResult } from '../types'

export async function listMedios(query: MediosQuery): Promise<PagedResult<MedioListItem>> {
  const params = new URLSearchParams()
  if (query.page !== undefined) params.set('page', String(query.page))
  if (query.pageSize !== undefined) params.set('pageSize', String(query.pageSize))
  if (query.activo !== undefined) params.set('activo', String(query.activo))
  if (query.tipo !== undefined) params.set('tipo', String(query.tipo))
  if (query.q !== undefined && query.q !== '') params.set('q', query.q)

  const response = await axiosClient.get<PagedResult<MedioListItem>>(
    '/api/v1/admin/medios',
    { params },
  )
  return response.data
}
