import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.types';

const params: NotifierParam[] = [
{ key: 'token', label: 'Token', type: 'password', required: true, placeholder: 'pushplus token' },
    { key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
    { key: 'content', label: '内容', type: 'text', required: true },
];

export const pushplusNotifier: Notifier = {
name: 'pushplus',
    label: 'PushPlus (微信)',
    params,
    async notify(params) {
        try {
            const resp = await fetch('https://www.pushplus.plus/send', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({
                    token: params.token,
                    title: params.title || 'CloudSearch',
                    content: params.content || '',
                }),
            });
            const data: any = await resp.json();
            if (data.code === 200)
                return { success: true, message: 'PushPlus 推送成功' };
            return { success: false, message: data.msg || `HTTP ${resp.status}` };
        }
        catch (err: any) {
            return { success: false, message: err.message };
        }
    },
};
