package com.agilex.healthcare.schedulingmanager.datalayer.fork;

import java.util.Map;

import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.agilex.healthcare.schedulingmanager.domain.SchedulingClinics;
import com.agilex.healthcare.schedulingmanager.domain.SchedulingSpecialties;
import com.agilex.healthcare.schedulingmanager.mdws.generatedwsdl.queryservice.TextArray;
import com.agilex.healthcare.schedulingmanager.util.TextArrayUtils;

/**
 * This class is the Fork/Join task runner for ProcessClinicsWithSpecialtiesTask.
 */
@Component
@Scope(value = "singleton")
@Lazy(true)
public class ProcessClinicsWithSpecialtiesTaskRunner extends ForkJoinTaskRunner<SchedulingClinics> {
    /**
     * Initializes the task with the passed parameters before invoking the parent runJob(), which starts
     * the Fork/Join process.
     *
     * @param task The Fork/Join task to run.
     * @param clinicsWithSpecialtiesArray The return result from the getClinicsWithSpecialties() MDWS call.
     * @param specialtyMap The map of clinic specialty values to displayable text retrieved from MDWS.
     * @param siteCode The site code for the getClinicsWithSpecialties() MDWS call.
     * @return SchedulingSpecialties
     */
    public SchedulingClinics runJob(final ProcessClinicsWithSpecialtiesTask task, final TextArray clinicsWithSpecialtiesArray, final Map<String, String> specialtyMap, final String siteCode) {
        task.init(clinicsWithSpecialtiesArray, specialtyMap, siteCode, 0, TextArrayUtils.size(clinicsWithSpecialtiesArray));
        return super.runJob(task);
    }
}
