package com.sundot.airport.item.service.portrait;

import com.sundot.airport.common.enums.portrait.IndicatorType;
import com.sundot.airport.common.service.portrait.AbstractModuleIndicatorService;
import com.sundot.airport.common.service.portrait.Indicator;
import com.sundot.airport.item.domain.portrait.ItemSeizureModuleIndicatorResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.*;

/**
 * 查获物模块指标服务实现
 * 处理查获物相关的指标计算
 */
@Service
public class ItemSeizureModuleIndicatorService extends AbstractModuleIndicatorService<ItemSeizureModuleIndicatorResult> {

    @Autowired
    private Set<Indicator<?>> indicators;

    private Set<IndicatorType> supportedIndicatorTypes = new HashSet<>();

    @Override
    public String getModuleName() {
        return "item";
    }

    @PostConstruct
    public void initSupportedIndicatorTypes() {
        // 初始化支持的指标类型
        if (indicators != null) {
            for (Indicator<?> indicator : indicators) {
                IndicatorType type = IndicatorType.fromCode(indicator.getName());
                if (type != null && !supportedIndicatorTypes.contains(type) && type.getModule().equals(getModuleName())) {
                    supportedIndicatorTypes.add(type);
                }
            }
        }
    }

    @Override
    protected ItemSeizureModuleIndicatorResult createResult() {
        return new ItemSeizureModuleIndicatorResult();
    }

    @Override
    protected Set<IndicatorType> getSupportedIndicatorTypes() {
        return supportedIndicatorTypes;
    }

    @Override
    protected Set<Indicator<?>> getIndicators() {
        return indicators;
    }

    @Override
    protected void setIndicatorResult(Indicator<?> indicator, ItemSeizureModuleIndicatorResult result) {
        // 直接调用指标的setResult方法，将值设置到结果对象中
        indicator.setResult(result);
    }
}