
package foundation.e.mail.mail.transport;

import foundation.e.mail.mail.K9MailLib;
import foundation.e.mail.mail.Message;
import foundation.e.mail.mail.MessagingException;
import foundation.e.mail.mail.Transport;
import foundation.e.mail.mail.store.StoreConfig;
import foundation.e.mail.mail.store.webdav.WebDavHttpClient;
import foundation.e.mail.mail.store.webdav.WebDavStore;
import timber.log.Timber;

import java.util.Collections;

public class WebDavTransport extends Transport {
    private WebDavStore store;

    public WebDavTransport(StoreConfig storeConfig) throws MessagingException {
        store = new WebDavStore(storeConfig, new WebDavHttpClient.WebDavHttpClientFactory());

        if (K9MailLib.isDebug())
            Timber.d(">>> New WebDavTransport creation complete");
    }

    @Override
    public void open() throws MessagingException {
        if (K9MailLib.isDebug())
            Timber.d( ">>> open called on WebDavTransport ");

        store.getHttpClient();
    }

    @Override
    public void close() {
    }

    @Override
    public void sendMessage(Message message) throws MessagingException {
        store.sendMessages(Collections.singletonList(message));
    }
}
