import {ApiCall} from "tsrpc";
import {Reqsendemail, Ressendemail} from "../../monopoly/protocols/email/Ptlsendemail";
import {EmailFun} from '../../public/email';
import {ReqEmail} from '../../monopoly/protocols/PtlEmail';

export default async function (call: ApiCall<Reqsendemail, Ressendemail>) {
    //1. 接受参数
    let prize = call.req.prize || [],
        title = call.req.title,
        content = call.req.content,
        sendType = call.req.sendType,
        uids = call.req.uids || [];
    //2. 发送邮件model
    let emailMsg: ReqEmail = {
        uid: '',
        type: 'system',
        title: '',
        content: '',
        lngTitle: title,
        lngContent: content
    }
    if (prize && prize.length > 0) emailMsg.prize = prize;
    //3. 全服邮件
    if (sendType == 2) {
        emailMsg.uid = "system"
        emailMsg.type = 'gm'
        EmailFun.addQuanFuEmail(emailMsg)
    } else {
        for (let i = 0; i < uids.length; i++) {
            emailMsg.uid = uids[i];
            EmailFun.addEmail(emailMsg);
        }
    }
    call.succ({result: 0, sendNum: sendType == 2 ? 0 : uids.length});
}