export function useAvatarService() {
    const api = useApi()

    async function upload(userId: number, file: Blob): Promise<{ avatarUrl: string }> {
        const formData = new FormData()
        formData.append('file', file, 'avatar.png')

        return api.post<{ avatarUrl: string }>(
            `/users/${userId}/avatar`,
            formData as unknown as Record<string, unknown>,
            {
                toastSuccessKey: 'profile.avatarUpdated',
            }
        )
    }

    async function remove(userId: number): Promise<void> {
        await api.delete(`/users/${userId}/avatar`)
    }

    function getUrl(userId: number): string {
        return `/api/users/${userId}/avatar`
    }

    return { upload, remove, getUrl }
}
