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

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

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

/**
 * 系统模块指标服务实现
 * 处理用户基本信息、资质、政治面貌等系统级指标
 */
@Service
public class SystemModuleIndicatorService extends AbstractModuleIndicatorService<IndicatorResult> {

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

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

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

    @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 IndicatorResult createResult() {
        return new IndicatorResult();
    }

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

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

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