import { apiRequest } from "@/shared/api/request"; import { API_ENDPOINTS, API_OPERATIONS, apiEndpointPath } from "@/shared/api/generated/endpoints"; import type { ApiList, AppBannerDto, AppBannerPayload, AppPopupDto, AppPopupPayload, AppSplashScreenDto, AppSplashScreenPayload, AppVersionDto, AppVersionPayload, EntityId, ExploreTabDto, ExploreTabPayload, H5LinkConfigDto, H5LinkConfigPayload, H5LinkConfigUpdatePayload, PageQuery, } from "@/shared/api/types"; export interface SystemMessagePushPayload { action_param?: string; action_type?: string; aggregate_type?: string; batch_size?: number; body?: string; message_type: "system"; producer_event_type?: string; summary: string; target_scope: "all_registered_users" | "user_ids"; title: string; user_ids?: string[]; } export interface SystemMessagePushResponse { command_id: string; created: boolean; job_id: string; message_type: string; status: string; target_scope: string; } export function createSystemMessagePushFanout(payload: SystemMessagePushPayload): Promise { const endpoint = API_ENDPOINTS.createFullServerNoticeFanout; return apiRequest( apiEndpointPath(API_OPERATIONS.createFullServerNoticeFanout), { body: payload, method: endpoint.method, }, ); } export function listH5Links(appCode: string): Promise> { const endpoint = API_ENDPOINTS.listH5Links; return apiRequest>(apiEndpointPath(API_OPERATIONS.listH5Links), { headers: appScopeHeaders(appCode), method: endpoint.method, }); } export function updateH5Links(appCode: string, payload: H5LinkConfigUpdatePayload): Promise> { const endpoint = API_ENDPOINTS.updateH5Links; return apiRequest, H5LinkConfigUpdatePayload>( apiEndpointPath(API_OPERATIONS.updateH5Links), { body: payload, headers: appScopeHeaders(appCode), method: endpoint.method, }, ); } export function createH5Link(appCode: string, payload: H5LinkConfigPayload): Promise { const endpoint = API_ENDPOINTS.createH5Link; return apiRequest(apiEndpointPath(API_OPERATIONS.createH5Link), { body: payload, headers: appScopeHeaders(appCode), method: endpoint.method, }); } export function updateH5Link(appCode: string, key: EntityId, payload: H5LinkConfigPayload): Promise { const endpoint = API_ENDPOINTS.updateH5Link; return apiRequest(apiEndpointPath(API_OPERATIONS.updateH5Link, { key }), { body: payload, headers: appScopeHeaders(appCode), method: endpoint.method, }); } export function deleteH5Link(appCode: string, key: EntityId): Promise<{ deleted: boolean }> { const endpoint = API_ENDPOINTS.deleteH5Link; return apiRequest<{ deleted: boolean }>(apiEndpointPath(API_OPERATIONS.deleteH5Link, { key }), { headers: appScopeHeaders(appCode), method: endpoint.method, }); } function appScopeHeaders(appCode: string) { // H5 配置是强 App 隔离数据;显式固定请求头可避免用户切换 App 时全局请求上下文变化导致写入错误租户。 return { "X-App-Code": String(appCode || "").trim().toLowerCase() }; } export function listExploreTabs(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listExploreTabs; return apiRequest>(apiEndpointPath(API_OPERATIONS.listExploreTabs), { method: endpoint.method, query, }); } export function createExploreTab(payload: ExploreTabPayload): Promise { const endpoint = API_ENDPOINTS.createExploreTab; return apiRequest(apiEndpointPath(API_OPERATIONS.createExploreTab), { body: payload, method: endpoint.method, }); } export function updateExploreTab(tabId: EntityId, payload: ExploreTabPayload): Promise { const endpoint = API_ENDPOINTS.updateExploreTab; return apiRequest( apiEndpointPath(API_OPERATIONS.updateExploreTab, { tab_id: tabId }), { body: payload, method: endpoint.method, }, ); } export function deleteExploreTab(tabId: EntityId): Promise<{ deleted: boolean }> { const endpoint = API_ENDPOINTS.deleteExploreTab; return apiRequest<{ deleted: boolean }>(apiEndpointPath(API_OPERATIONS.deleteExploreTab, { tab_id: tabId }), { method: endpoint.method, }); } export function listBanners(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listBanners; return apiRequest>(apiEndpointPath(API_OPERATIONS.listBanners), { method: endpoint.method, query, }); } export function createBanner(payload: AppBannerPayload): Promise { const endpoint = API_ENDPOINTS.createBanner; return apiRequest(apiEndpointPath(API_OPERATIONS.createBanner), { body: payload, method: endpoint.method, }); } export function updateBanner(bannerId: EntityId, payload: AppBannerPayload): Promise { const endpoint = API_ENDPOINTS.updateBanner; return apiRequest( apiEndpointPath(API_OPERATIONS.updateBanner, { banner_id: bannerId }), { body: payload, method: endpoint.method, }, ); } export function deleteBanner(bannerId: EntityId): Promise<{ deleted: boolean }> { const endpoint = API_ENDPOINTS.deleteBanner; return apiRequest<{ deleted: boolean }>(apiEndpointPath(API_OPERATIONS.deleteBanner, { banner_id: bannerId }), { method: endpoint.method, }); } export function listSplashScreens(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listSplashScreens; return apiRequest>(apiEndpointPath(API_OPERATIONS.listSplashScreens), { method: endpoint.method, query, }); } export function createSplashScreen(payload: AppSplashScreenPayload): Promise { const endpoint = API_ENDPOINTS.createSplashScreen; return apiRequest(apiEndpointPath(API_OPERATIONS.createSplashScreen), { body: payload, method: endpoint.method, }); } export function updateSplashScreen(splashId: EntityId, payload: AppSplashScreenPayload): Promise { const endpoint = API_ENDPOINTS.updateSplashScreen; return apiRequest( apiEndpointPath(API_OPERATIONS.updateSplashScreen, { splash_id: splashId }), { body: payload, method: endpoint.method, }, ); } export function deleteSplashScreen(splashId: EntityId): Promise<{ deleted: boolean }> { const endpoint = API_ENDPOINTS.deleteSplashScreen; return apiRequest<{ deleted: boolean }>( apiEndpointPath(API_OPERATIONS.deleteSplashScreen, { splash_id: splashId }), { method: endpoint.method, }, ); } export function listPopups(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listPopups; return apiRequest>(apiEndpointPath(API_OPERATIONS.listPopups), { method: endpoint.method, query, }); } export function createPopup(payload: AppPopupPayload): Promise { const endpoint = API_ENDPOINTS.createPopup; return apiRequest(apiEndpointPath(API_OPERATIONS.createPopup), { body: payload, method: endpoint.method, }); } export function updatePopup(popupId: EntityId, payload: AppPopupPayload): Promise { const endpoint = API_ENDPOINTS.updatePopup; return apiRequest( apiEndpointPath(API_OPERATIONS.updatePopup, { popup_id: popupId }), { body: payload, method: endpoint.method, }, ); } export function deletePopup(popupId: EntityId): Promise<{ deleted: boolean }> { const endpoint = API_ENDPOINTS.deletePopup; return apiRequest<{ deleted: boolean }>(apiEndpointPath(API_OPERATIONS.deletePopup, { popup_id: popupId }), { method: endpoint.method, }); } export function listAppVersions(query: PageQuery = {}): Promise> { const endpoint = API_ENDPOINTS.listAppVersions; return apiRequest>(apiEndpointPath(API_OPERATIONS.listAppVersions), { method: endpoint.method, query, }); } export function createAppVersion(payload: AppVersionPayload): Promise { const endpoint = API_ENDPOINTS.createAppVersion; return apiRequest(apiEndpointPath(API_OPERATIONS.createAppVersion), { body: payload, method: endpoint.method, }); } export function updateAppVersion(versionId: EntityId, payload: AppVersionPayload): Promise { const endpoint = API_ENDPOINTS.updateAppVersion; return apiRequest( apiEndpointPath(API_OPERATIONS.updateAppVersion, { version_id: versionId }), { body: payload, method: endpoint.method, }, ); } export function deleteAppVersion(versionId: EntityId): Promise<{ deleted: boolean }> { const endpoint = API_ENDPOINTS.deleteAppVersion; return apiRequest<{ deleted: boolean }>( apiEndpointPath(API_OPERATIONS.deleteAppVersion, { version_id: versionId }), { method: endpoint.method, }, ); }