package _VisualDVM.Passes.All;
import _VisualDVM.Passes.Server.ComponentsServerPass;
import _VisualDVM.Repository.EmailMessage;
import _VisualDVM.Repository.Server.ServerCode;

import java.util.Vector;
public class Email extends ComponentsServerPass<EmailMessage> {
    Vector<String> recipients;
    @Override
    protected boolean requestNeedsAnimation() {
        return false;
    }
    @Override
    protected boolean needsAnimation() {
        return true;
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        recipients = null;
        if (args.length <= 1) {
            return false;
        }
        target = (EmailMessage) args[0];
        if (args[1] instanceof Vector) {
            recipients = (Vector<String>) args[1];
            return true;
        } else if (args[1] instanceof String) {
            recipients = new Vector<>();
            for (int i = 1; i < args.length; ++i) {
                recipients.add((String) args[i]);
            }
            return true;
        }
        return false;
    }
    @Override
    protected void body() throws Exception {
        int i = 0;
        for (String address : recipients) {
            ShowProgress(recipients.size(), i, true);
            SendRequest(ServerCode.Email, address, target);
            ++i;
        }
    }
}

