import { ApiCall } from "tsrpc";
import { EmailFun } from '../../public/email';
import { ReqAllRemove, ResAllRemove } from "../../shared/protocols/email/PtlAllRemove";

export default async function (call: ApiCall<ReqAllRemove, ResAllRemove>) {
    //  邮件已读 并且 (没有奖励 或者 (有奖励 并且 领取了))
    let emailList = (await EmailFun.getAllEmail(call.uid, true)).filter(email => (
        email.emailRead && (!email.prizeData || (email.prizeData?.prize.length > 0 && email.prizeData?.isGet))
    ));

    if (emailList.length < 1) return call.error(globalThis.lng.email_2);

    call.succ(EmailFun.removeEmail(call.uid, emailList.map(email => email._id)));
}