// Todas as chamadas vão via /api/proxy/** (BFF injeta Bearer + tenant headers). // Cada método retorna o envelope cru do core-api: { data, message, statusCode, ... } // — exceto rotas binárias (PDF), que retornam ArrayBuffer. const FETCH_HEADERS = { 'X-Requested-With': 'fetch' } function proxyUrl(path) { return `/api/proxy${path}` } export const portalService = { // ─── Painel ────────────────────────────────────────────────────────────── getPainelResumo() { return $fetch(proxyUrl('/contribuinte/painel/resumo'), { headers: FETCH_HEADERS }) }, getAtividades(pagina = 0, tamanho = 5) { return $fetch(proxyUrl('/contribuinte/painel/atividades'), { headers: FETCH_HEADERS, query: { pagina, tamanho }, }) }, // ─── Débitos ───────────────────────────────────────────────────────────── getDebitos(params = {}) { return $fetch(proxyUrl('/contribuinte/debitos'), { headers: FETCH_HEADERS, query: params, }) }, emitirGuia(idDebito) { return $fetch(proxyUrl(`/contribuinte/debitos/${idDebito}/guia`), { headers: FETCH_HEADERS, responseType: 'arrayBuffer', }) }, // ─── Certidões ─────────────────────────────────────────────────────────── getCertidoes() { return $fetch(proxyUrl('/contribuinte/certidoes'), { headers: FETCH_HEADERS }) }, reemitirCertidao(idCertidao) { return $fetch(proxyUrl(`/contribuinte/certidoes/${idCertidao}/pdf`), { headers: FETCH_HEADERS, responseType: 'arrayBuffer', }) }, // ─── Alvarás ───────────────────────────────────────────────────────────── getAlvaras(params = {}) { return $fetch(proxyUrl('/contribuinte/alvaras'), { headers: FETCH_HEADERS, query: params, }) }, // ─── Pagamentos ────────────────────────────────────────────────────────── getPagamentos(params = {}) { return $fetch(proxyUrl('/contribuinte/pagamentos'), { headers: FETCH_HEADERS, query: params, }) }, getComprovante(idPagamento) { return $fetch(proxyUrl(`/contribuinte/pagamentos/${idPagamento}/comprovante`), { headers: FETCH_HEADERS, responseType: 'arrayBuffer', }) }, // ─── Dados cadastrais ──────────────────────────────────────────────────── getDadosCadastrais() { return $fetch(proxyUrl('/contribuinte/dados'), { headers: FETCH_HEADERS }) }, atualizarContato(payload) { return $fetch(proxyUrl('/contribuinte/dados/contato'), { method: 'PUT', headers: FETCH_HEADERS, body: payload, }) }, }