package com.eactive.testmaster.loadtest.service;

import com.eactive.testmaster.loadtest.dto.LoadTestDTO;
import java.util.Map;
import java.util.concurrent.Callable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CallableVirtualUser implements Callable<String> {

    private static final Logger logger = LoggerFactory.getLogger(VirtualUser.class);

    private final CallableLoadTestService loadTestService;

    private LoadTestDTO loadTest;
    private Map<String, String> data;

    public CallableVirtualUser(CallableLoadTestService loadTestService) {
        this.loadTestService = loadTestService;
    }

    @Override
    public String call() throws Exception {
        try {
            // Simulate user action
            Thread.sleep(1000); // Replace with actual user action
            loadTestService.sendLoadTestUpdate(loadTest.getId(), "Virtual user completed");
            return "Completed";
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt(); // Preserve interrupt status
            logger.debug("Task interrupted");
            return "Interrupted";
        }
    }
}
