import { apiEndpoints } from "@/lib/api/endpoints"; import { fetchWithAuth } from "@/lib/auth/client"; import type { CollaborationRequestItem, CollaborationRequestsResponse, DeviceItem, FollowListResponse, FollowStatusResponse, NotificationsResponse, PostsResponse, PresenceResponse, RegisterDevicePayload, SuccessMessage, UnregisterDevicePayload, } from "@/types/api"; export async function getUserPresence(userId: string) { return fetchWithAuth(apiEndpoints.users.publicPresence(userId)); } export async function listUserPosts( userId: string, params: Record = {}, ) { return fetchWithAuth(apiEndpoints.users.publicPosts(userId, params)); } export async function followUser(userId: string) { return fetchWithAuth(apiEndpoints.users.follow(userId), { method: "POST", body: JSON.stringify({}), }); } export async function unfollowUser(userId: string) { return fetchWithAuth(apiEndpoints.users.unfollow(userId), { method: "DELETE", }); } export async function getFollowStatus(userId: string) { return fetchWithAuth(apiEndpoints.users.followStatus(userId)); } export async function listUserFollowers( userId: string, params: Record = {}, ) { return fetchWithAuth(apiEndpoints.users.followers(userId, params)); } export async function listUserFollowing( userId: string, params: Record = {}, ) { return fetchWithAuth(apiEndpoints.users.following(userId, params)); } export async function registerDevice(payload: RegisterDevicePayload) { return fetchWithAuth(apiEndpoints.devices.register, { method: "POST", body: JSON.stringify(payload), }); } export async function unregisterDevice(payload: UnregisterDevicePayload) { return fetchWithAuth(apiEndpoints.devices.unregister, { method: "POST", body: JSON.stringify(payload), }); } export async function createCollaborationRequest(postId: string, targetUserId: string) { return fetchWithAuth(apiEndpoints.collaborationRequests.create(postId), { method: "POST", body: JSON.stringify({ targetUserId }), }); } export async function listCollaborationRequests( params: Record = {}, ) { return fetchWithAuth(apiEndpoints.collaborationRequests.list(params)); } export async function approveCollaborationRequest(requestId: string) { return fetchWithAuth(apiEndpoints.collaborationRequests.approve(requestId), { method: "PATCH", body: JSON.stringify({}), }); } export async function rejectCollaborationRequest(requestId: string) { return fetchWithAuth(apiEndpoints.collaborationRequests.reject(requestId), { method: "PATCH", body: JSON.stringify({}), }); } export async function listMyNotifications( params: Record = {}, ) { return fetchWithAuth(apiEndpoints.notifications.mine(params)); } export async function getMyUnreadNotificationCount() { return fetchWithAuth<{ unreadCount: number }>(apiEndpoints.notifications.unreadCount); } export async function markMyNotificationRead(notificationId: string) { return fetchWithAuth(apiEndpoints.notifications.markRead(notificationId), { method: "PATCH", body: JSON.stringify({}), }); } export async function markAllMyNotificationsRead() { return fetchWithAuth(apiEndpoints.notifications.markAllRead, { method: "PATCH", body: JSON.stringify({}), }); } export type MobileSocialRouteGroup = { title: string; routes: string[]; }; export const mobileSocialRouteGroups: MobileSocialRouteGroup[] = [ { title: "users", routes: [ "GET /users/:userId", "GET /users/:userId/presence", "GET /users/:userId/posts", "GET /users/:userId/profile-overview", ], }, { title: "follows", routes: [ "POST /users/:userId/follow", "DELETE /users/:userId/follow", "GET /users/:userId/follow-status", "GET /users/:userId/followers", "GET /users/:userId/following", "GET /users/me/followers", "GET /users/me/following", ], }, { title: "devices", routes: ["POST /devices/register", "POST /devices/unregister"], }, { title: "collaborationRequests", routes: [ "POST /posts/:postId/collaboration-requests", "GET /collaboration-requests", "PATCH /collaboration-requests/:requestId/approve", "PATCH /collaboration-requests/:requestId/reject", ], }, { title: "notifications", routes: [ "GET /notifications", "GET /notifications/unread-count", "PATCH /notifications/:notificationId/read", "PATCH /notifications/read-all", ], }, ];