import api from "./api"; export interface UserRole { id: any; user_id: string; role: string; [key: string]: any; } export interface User { id: any; email: string; [key: string]: any; } export interface FullUserData { user: User; profile: any; roles: string[]; permissions: any; } export const usuariosApi = { listRoles: async (): Promise => { const response = await api.get("/rest/v1/user_roles"); return response.data; }, createUser: async (data: { email: string; full_name: string; phone?: string; phone_mobile?: string; role: string; cpf?: string; create_patient_record?: boolean; }): Promise => { try { const response = await api.post("/functions/v1/create-user", data, { headers: { "Content-Type": "application/json", apikey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || "", Authorization: `Bearer ${ typeof window !== "undefined" ? localStorage.getItem("supabase-access-token") || "" : "" }`, }, }); return response.data; } catch (error: any) { console.error("❌ Erro no createUser:", error.response?.data || error); throw error; } }, getCurrentUser: async (): Promise => { const response = await api.post( "/functions/v1/user-info", {}, { headers: { "Content-Type": "application/json" } } ); return response.data; }, getFullData: async (userId: string): Promise => { const response = await api.post( "/functions/v1/user-info-by-id", { user_id: userId }, { headers: { "Content-Type": "application/json" } } ); return response.data; }, };