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

const params: NotifierParam[] = [
{ key: 'sendkey', label: 'SendKey', type: 'password', required: true, placeholder: 'Server酱 SendKey' },
    
];

export const serverchanNotifier: Notifier = {
name: 'serverchan',
    label: 'Server酱',
    params,
    async notify(params) {
        try {
            const sendkey = params.sendkey;
            const resp = await fetch(`https://sctapi.ftqq.com/${sendkey}.send`, {
                method: 'POST',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                body: new URLSearchParams({ title: params.title || 'CloudSearch', desp: params.content || '' }).toString(),
            });
            const data: any = await resp.json();
            if (data.code === 0)
                return { success: true, message: 'Server酱 推送成功' };
            return { success: false, message: data.message || `HTTP ${resp.status}` };
        }
        catch (err: any) {
            return { success: false, message: err.message };
        }
    },
};
