package com.friday.distributor.frame;

import com.friday.base.common.response.DubboResult;
import com.friday.distributor.bean.Job;
import com.friday.distributor.bean.TaieJobExecInfo;
import com.friday.operation.api.distributor.dto.TaskResultDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author  YaoYao
 * @Date Created In 2023/3/8 13:23
 * @Description 总业务策略模式（分别策略到RPA/AI/PROGRAM的框架服务）
 * @ModifiedBy
 */
@Service
@Slf4j
public class GeneralStrategyContext {

    private final static String STRATEGY_SERVICE_NAME_SUFFIX = "ExecFrameService";
    private final Map<String, IBizTypeStrategyContext> generalStrategyMap = new ConcurrentHashMap<>();

    @Autowired
    public GeneralStrategyContext(Map<String, IBizTypeStrategyContext> generalStrategyMap) {
        generalStrategyMap.forEach(this.generalStrategyMap::put);
    }

    public DubboResult<String> asyncStartTaieJob(Job job) {
        return generalStrategyMap.get(job.getBizType() + STRATEGY_SERVICE_NAME_SUFFIX).asyncStartTaieJob(job);
    }

    public DubboResult<TaskResultDto> syncStartTaieJob(Job job) {
        return generalStrategyMap.get(job.getBizType() + STRATEGY_SERVICE_NAME_SUFFIX).syncStartTaieJob(job);
    }

    public DubboResult stopTaieJob(Job job) {
        return generalStrategyMap.get(job.getBizType() + STRATEGY_SERVICE_NAME_SUFFIX).stopTaieJob(job);
    }

    public DubboResult<TaieJobExecInfo> getTaieJobExecDetail(Job job) {
        return generalStrategyMap.get(job.getBizType() + STRATEGY_SERVICE_NAME_SUFFIX).getTaieJobExecDetail(job);
    }

}
