package de.ivu.elect.business.email.boundary;

import de.ivu.elect.business.email.entity.Email;
import de.ivu.elect.business.email.entity.EmailStatusType;
import de.ivu.elect.business.email.entity.EmailVorgang;

import javax.ejb.Stateless;
import java.util.List;

@Stateless
public class EmailEdit extends AbstractEmailEdit {

  public EmailEdit() {
    super();
  }

  public void sendeEmailsErneut(List<Email> emails) {
    if (emails == null) {
      return;
    }
    for (Email email : emails) {
      Email attachedEmail = extendedDao.attach(email);
      attachedEmail.setStatus(EmailStatusType.ZU_VERSENDEN);
      attachedEmail.setFehlermeldung(null);
      save(attachedEmail);
    }
  }

  public void sendeAlleErneut(EmailVorgang emailVorgang) {
    extendedDao.updateStatusAndFehlermeldungByEmailVorgang(emailVorgang, EmailStatusType.ZU_VERSENDEN, "");
  }

  public void sendeFehlerhafteErneut(EmailVorgang emailVorgang) {
    extendedDao.updateStatusAndFehlermeldungByEmailVorgangAndStatus(emailVorgang, EmailStatusType.FEHLER,
        EmailStatusType.ZU_VERSENDEN, "");
  }

  public void sendenAbbrechen(EmailVorgang emailVorgang) {
    extendedDao.updateStatusByEmailVorgangAndStatus(emailVorgang, EmailStatusType.ZU_VERSENDEN, EmailStatusType.ABGEBROCHEN);
  }
}
