import { NotificationApi, Configuration, type NotificationDto, type PagedNotificationDto, type CreateNotificationDto } from '~/.api-client' import { cleanDoubleSlashes, withoutTrailingSlash } from 'ufo' import { wrappedFetchWrap } from '~/utils/wrappedFetch' export function useNotificationApi() { const appBaseUrl = useRuntimeConfig().app.baseURL const { serverApiBasePath, clientProxyBasePath } = useRuntimeConfig().public const basePath = withoutTrailingSlash( cleanDoubleSlashes( import.meta.client ? appBaseUrl + clientProxyBasePath : useRequestURL().origin + clientProxyBasePath + serverApiBasePath ) ) const notificationApiClient = new NotificationApi( new Configuration({ basePath, fetchApi: wrappedFetchWrap(useRequestFetch()) }) ) async function createNotification(createNotificationDto: CreateNotificationDto): Promise { return notificationApiClient.createNotification({ createNotificationDto }) } async function getNotifications(page?: number, size?: number): Promise { return notificationApiClient.getNotifications({ page, size }) } async function getUnreadNotifications(): Promise { return notificationApiClient.getUnreadNotifications() } async function getUnreadNotificationCount(): Promise { return notificationApiClient.getUnreadNotificationCount() } async function markAllNotificationsAsRead(): Promise { return notificationApiClient.markAllNotificationsAsRead() } async function markNotificationAsRead(id: string): Promise { return notificationApiClient.markNotificationAsRead({ id }) } return { createNotification, getNotifications, getUnreadNotifications, getUnreadNotificationCount, markAllNotificationsAsRead, markNotificationAsRead } }