package cn.com.poc.ai_software_copyright.factory;

import cn.com.poc.ai_software_copyright.contant.AiSoftWareCopyRightEnum;
import cn.com.poc.ai_software_copyright.strategy.DocGenerationStrategy;
import cn.com.poc.ai_software_copyright.strategy.impl.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.EnumMap;
import java.util.Map;

/**
 * 文档生成策略工厂
 */
@Component
public class DocGenerationStrategyFactory {

    @Autowired
    private SourceCodeGenerationStrategy sourceCodeGenerationStrategy;

    @Autowired
    private PhOperatingManualGenerationStrategy phOperatingManualGenerationStrategy;

    @Autowired
    private PcOperatingManualGenerationStrategy pcOperatingManualGenerationStrategy;

    @Autowired
    private InformationGenerationStrategy informationGenerationStrategy;

    private final Map<AiSoftWareCopyRightEnum.DOC_TYPE, DocGenerationStrategy> strategies = new EnumMap<>(AiSoftWareCopyRightEnum.DOC_TYPE.class);

    @PostConstruct
    public void init() {
        strategies.put(AiSoftWareCopyRightEnum.DOC_TYPE.source_code, sourceCodeGenerationStrategy);
        strategies.put(AiSoftWareCopyRightEnum.DOC_TYPE.ph_operating_manual, phOperatingManualGenerationStrategy);
        strategies.put(AiSoftWareCopyRightEnum.DOC_TYPE.pc_operating_manual, pcOperatingManualGenerationStrategy);
        strategies.put(AiSoftWareCopyRightEnum.DOC_TYPE.information, informationGenerationStrategy);
    }

    public DocGenerationStrategy getStrategy(AiSoftWareCopyRightEnum.DOC_TYPE docType) {
        DocGenerationStrategy strategy = strategies.get(docType);
        if (strategy == null) {
            throw new IllegalArgumentException("不支持的文档类型：" + docType);
        }
        return strategy;
    }
}