import axios from 'axios'

const client = axios.create({
  baseURL: process.env.LEGAL_SERVICE_URL ?? 'http://localhost:3200',
  timeout: 8000,
})

export async function getMatters(params: { status?: string; limit?: number } = {}) {
  const res = await client.get('/matters', { params })
  return res.data as { items: any[]; total: number }
}

export async function getUpcomingHearings(days = 7) {
  const res = await client.get('/hearings/upcoming', { params: { days } })
  return res.data as any[]
}

export async function getUnbilledTimeEntries() {
  const res = await client.get('/time-entries', { params: { billed: false, limit: 500 } })
  return res.data as { items: any[]; total: number }
}

export async function getClientFolders(params: { status?: string; limit?: number } = {}) {
  const res = await client.get('/client-folders', { params })
  return res.data as { items: any[]; total: number }
}

export async function getRetainerBalance(clientFolderId: string) {
  const res = await client.get(`/client-folders/${clientFolderId}/retainer/balance`)
  return res.data
}
