/** * Serviço de endereços via BFF/compatibilidade. */ const BFF_BASE_URL = process.env.NEXT_PUBLIC_BFF_API_URL || ''; export interface EnderecoData { $id?: string; id?: string; titulo?: string; cep: string; logradouro: string; bairro: string; numero: string; complemento?: string; cidade: string; estado: string; pais?: string; latitude?: number; longitude?: number; principal?: boolean; $createdAt?: string; $updatedAt?: string; } export type Endereco = EnderecoData; interface ServiceResponse { success: boolean; data?: T; documents?: T[]; total?: number; error?: string; message?: string; } const emptyList = (): ServiceResponse => ({ success: true, documents: [], total: 0 }); const removed = (message = 'Service removido'): ServiceResponse => ({ success: false, error: message, message }); export const enderecoService = { buscarPorId: async (_enderecoId: string): Promise => null, buscarPorCep: async (cep: string): Promise | null> => { try { const cleanCep = cep.replace(/\D/g, ''); if (cleanCep.length !== 8) return null; const response = await fetch(`https://cep.awesomeapi.com.br/json/${cleanCep}`); if (!response.ok) return null; const data = await response.json(); return { cep: data.cep, logradouro: data.address, bairro: data.district, cidade: data.city, estado: data.state, }; } catch { return null; } }, listar: async (_page = 1, _limit = 10) => emptyList(), buscar: async (_termo: string, _page = 1, _limit = 10) => emptyList(), buscarPorUserId: async () => emptyList(), criar: async (_data?: EnderecoData) => removed(), atualizar: async (_id?: string, _data?: Partial) => removed(), excluir: async (_id?: string) => removed(), deletar: async (_id?: string) => removed(), };