// Copyright 2026 Arctel.net // SPDX-License-Identifier: Apache-2.0 import { BaseService } from '@/lib/services/core'; import type { ChannelDefinition, CreateChannelRequest, CreatePushEventRequest, EventMetadata, ListPushHistoriesRequest, ListPushHistoriesResponse, PushChannel, PushEvent, TestChannelRequest, TestPushRequest, UpdateChannelRequest, UpdatePushEventRequest, } from './types'; /** * 通知推送服务类 */ export class PushService extends BaseService { protected static readonly basePath = '/api/v1/admin/push'; /** * 获取通知事件列表 */ static async listEvents(): Promise { return this.get('/events'); } /** * 获取系统内置通知事件元数据列表 */ static async listBuiltInEvents(): Promise { return this.get('/events/builtin'); } /** * 创建通知事件配置 */ static async createEvent(data: CreatePushEventRequest): Promise { return this.post( '/events', data as unknown as Record, ); } /** * 更新指定通知事件配置 */ static async updateEvent( id: number, data: UpdatePushEventRequest, ): Promise { return this.put( `/events/${id}`, data as unknown as Record, ); } /** * 删除指定通知事件配置 */ static async deleteEvent(id: number): Promise { return this.delete(`/events/${id}`); } /** * 快捷切换事件启用状态 */ static async toggleEvent(id: number): Promise { return this.post(`/events/${id}/toggle`); } /** * 分页查询通知推送历史 */ static async listHistories( params: ListPushHistoriesRequest, ): Promise { return this.get( '/histories', params as unknown as Record, ); } /** * 发送测试推送进行联通性校验 */ static async testPush(data: TestPushRequest): Promise { return this.post('/test', data as unknown as Record); } /** * 获取所有消息通道 */ static async listChannels(): Promise { return this.get('/channels'); } /** * 创建新的消息通道 */ static async createChannel(data: CreateChannelRequest): Promise { return this.post( '/channels', data as unknown as Record, ); } /** * 更新指定消息通道 */ static async updateChannel( id: number, data: UpdateChannelRequest, ): Promise { return this.put( `/channels/${id}`, data as unknown as Record, ); } /** * 删除指定消息通道 */ static async deleteChannel(id: number): Promise { return this.delete(`/channels/${id}`); } /** * 测试消息通道连通性 */ static async testChannel(data: TestChannelRequest): Promise { return this.post( '/channels/test', data as unknown as Record, ); } /** * 获取各消息通道的动态表单定义 */ static async listChannelDefinitions(): Promise { return this.get('/channels/definitions'); } }