import { AxiosInstance } from "axios"; import { BrainRoleType } from "@/lib/components/NavBar/components/NavItems/components/BrainsDropDown/components/BrainActions/types"; import { Brain, MinimalBrainForUser } from "@/lib/context/BrainProvider/types"; import { Document } from "@/lib/types/Document"; export const getBrainDocuments = async ( brainId: string, axiosInstance: AxiosInstance ): Promise => { const response = await axiosInstance.get<{ documents: Document[] }>( `/explore/?brain_id=${brainId}` ); return response.data.documents; }; export const createBrain = async ( name: string, axiosInstance: AxiosInstance ): Promise => { const createdBrain = ( await axiosInstance.post(`/brains/`, { name }) ).data; return createdBrain; }; export const getBrain = async ( brainId: string, axiosInstance: AxiosInstance ): Promise => { const brain = ( await axiosInstance.get(`/brains/${brainId}/`) ).data; return brain; }; export const deleteBrain = async ( brainId: string, axiosInstance: AxiosInstance ): Promise => { await axiosInstance.delete(`/brains/${brainId}/subscription`); }; export const getDefaultBrain = async ( axiosInstance: AxiosInstance ): Promise => { return (await axiosInstance.get(`/brains/default/`)) .data; }; export const getBrains = async ( axiosInstance: AxiosInstance ): Promise => { const brains = ( await axiosInstance.get<{ brains: MinimalBrainForUser[] }>(`/brains/`) ).data; return brains.brains; }; export type Subscription = { email: string; rights: BrainRoleType }; export const addBrainSubscriptions = async ( brainId: string, subscriptions: Subscription[], axiosInstance: AxiosInstance ): Promise => { await axiosInstance.post(`/brains/${brainId}/subscription`, subscriptions); }; export const getBrainUsers = async ( brainId: string, axiosInstance: AxiosInstance ): Promise => { return (await axiosInstance.get(`/brains/${brainId}/users`)) .data; }; export type SubscriptionUpdatableProperties = { rights: BrainRoleType | null; }; export const updateBrainAccess = async ( brainId: string, userEmail: string, subscription: SubscriptionUpdatableProperties, axiosInstance: AxiosInstance ): Promise => { await axiosInstance.put(`/brains/${brainId}/subscription`, { ...subscription, email: userEmail, }); };