package com.flowable.local.work.model;

import com.flowable.spring.boot.properties.FlowableMailProperties;
import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.ServerSetup;

import jakarta.mail.internet.MimeMessage;
import org.springframework.stereotype.Component;

import static com.icegreen.greenmail.util.ServerSetup.PROTOCOL_SMTP;

@Component
public class TestMailServer {
    private GreenMail greenMail;

    private final FlowableMailProperties flowableMailProperties;
    public TestMailServer(FlowableMailProperties flowableMailProperties) {
        this.flowableMailProperties = flowableMailProperties;
    }

    public void setup() {
        greenMail = new GreenMail(new ServerSetup(flowableMailProperties.getPort(), flowableMailProperties.getHost(), PROTOCOL_SMTP));
        greenMail.start();
    }

    public void stop() {
        greenMail.stop();
    }

    public MimeMessage[]  getMessages() {
        return greenMail.getReceivedMessages();
    }
}
