package com.ecep.contract;

import com.fasterxml.jackson.core.JsonProcessingException;

import java.util.Locale;
import java.util.logging.Level;

public interface WebSocketClientTasker {
    String getTaskName();

    void updateMessage(Level level, String message);

    void updateTitle(String title);

    void updateProgress(long current, long total);

    default Object callRemoteTask(MessageHolder holder, Locale locale, Object... args) {
        WebSocketClientService webSocketService = SpringApp.getBean(WebSocketClientService.class);
        webSocketService.withSession(session -> {
            try {
                session.submitTask(this, locale, args);
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        });

        return null;
    }
}
