package com.lutao.cloud.consume.factory;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 命令策略工厂
 *
 * @author yx
 * @date 2023/07/19
 */
@Component
public class CommandStrategyFactory {

    private static Map<String, CommandStrategy<?>> strategyMap;


    @Resource(name = "fireParametersTagStrategy")
    private CommandStrategy fireParametersTagStrategy;
    @Resource(name = "gasParametersTagStrategy")
    private CommandStrategy gasParametersTagStrategy;
    @Resource(name = "hazardousGasParametersTagStrategy")
    private CommandStrategy hazardousGasParametersTagStrategy;
    @Resource(name = "processParametersTagStrategy")
    private CommandStrategy processParametersTagStrategy;

    @PostConstruct
    public void init() {

        strategyMap = new HashMap<>();

        strategyMap.put("app_info", new AppInfoStrategy());
        strategyMap.put("change_info", new ChangeInfoStrategy());
        strategyMap.put("platform_info", new PlatformInfoStrategy());
        strategyMap.put("person_info", new PersonInfoStrategy());
        strategyMap.put("person_certificate", new PersonCertificateStrategy());
        strategyMap.put("dangerous_act_record", new DangerousActRecordStrategy());
        strategyMap.put("person_in_info", new PersonIniInfoStrategy());
        strategyMap.put("person_out_info", new PersonOutInfoStrategy());
        strategyMap.put("contractor_manage", new ContractorManageStrategy());
        strategyMap.put("high_risk_operation", new HighRiskOperationStrategy());
        strategyMap.put("emergency_record", new EmergencyRecordStrategy());
        strategyMap.put("change_info_review", new ChangeInfoReviewStrategy());
        strategyMap.put("record_manage", new RecordManageStrategy());
        strategyMap.put("matters_manager", new MattersManagerStrategy());
        strategyMap.put("giveup_mine_report", new GiveUpMineReportStrategy());
        strategyMap.put("security_risk_assessment", new SecurityRiskAssessmentStrategy());
        strategyMap.put("problem_rectification_detail", new ProblemRectificationDetailStrategy());
        strategyMap.put("fire_parameters_tag", this.fireParametersTagStrategy);
        strategyMap.put("gas_parameters_tag", this.gasParametersTagStrategy);
        strategyMap.put("hazardous_gas_parameters_tag", this.hazardousGasParametersTagStrategy);
        strategyMap.put("process_parameters_tag", this.processParametersTagStrategy);
        strategyMap.put("prof_equipment_info", new ProEquipmentInfoStrategy());
        strategyMap.put("valve_status_clm", new ValueStausClmStrategy());
        strategyMap.put("video_equipment_info", new VideoEquipmentInfoStrategy());
        strategyMap.put("work_status_clm", new WorkStatusClmStrategy());
        strategyMap.put("tag_alarm_clm", new TagAlarmClmStrategy());
        strategyMap.put("platform_person_info", new PlatformPersonInfoStrategy());
        strategyMap.put("platform_person_time_info", new PlatformPersonTimeInfoStrategy());
        strategyMap.put("division_inspection_detail", new DivisionInspectionDetailStrategy());
        strategyMap.put("ministerial_supervision_detail", new MinisteriaSupervisionDetailStrategy());
        // 动态数据
        strategyMap.put("perception_monitor_info", new PerceptionMonitorInfoStrategy());
        strategyMap.put("perception_monitor_fire_info", new PerceptionMonitorFireInfoStrategy());
        strategyMap.put("perception_monitor_gas_info", new PerceptionMonitorGasInfoStrategy());
        strategyMap.put("perception_monitor_hazardous_gas_info", new PerceptionMonitorHazardousGasInfoStrategy());
        strategyMap.put("atmosphere_monitor_info", new AtmosphereMonitorInfoStrategy());
        strategyMap.put("valve_status_monitor", new ValueStausMonitorStrategy());
        strategyMap.put("work_status_monitor", new WorkStatusMonitorStrategy());


    }

    public <T> CommandStrategy<T> createStrategy(String tableName) {
        CommandStrategy<?> strategy = strategyMap.get(tableName);

        if (strategy == null) {
            throw new IllegalArgumentException("Unknown the table name");
        }

        return (CommandStrategy<T>) strategy;
    }
}
