package com.jiayue.ipfcst.dataexchange.service.equipmentstatusdata;

import com.jiayue.ipfcst.common.data.abst.equipmentinfo.AbstractEquipmentInfo;
import com.jiayue.ipfcst.common.data.constant.enums.EquipmentTypeEnum;
import com.jiayue.ipfcst.common.data.repository.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 设备属性描述表的操作service
 *
 * @author 修唯xiuwei
 * @version 3.0
 */
@Service
public class EquipmentInfoService {

  final
  WeatherStationInfoRepository weatherStationInfoRepository;

  final
  WindTowerInfoRepository windTowerRepository;

  final
  WindTurbineInfoRepository windTurbineRepository;

  final
  InverterInfoRepository inverterRepository;

  final BoosterStationInfoRepository boosterStationInfoRepository;

  final AGC_AVCInfoRepository agcAvcInfoRepository;

  final CollectingPowerLineInfoRepository collectingPowerLineInfoRepository;

  final SubsidiaryEquipmentInfoRepository subsidiaryEquipmentInfoRepository;

  @Autowired
  PowerStationStatusDataRepository powerStationStatusDataRepository;

  public EquipmentInfoService(WeatherStationInfoRepository weatherStationInfoRepository,
                              WindTowerInfoRepository windTowerRepository, WindTurbineInfoRepository windTurbineRepository,
                              InverterInfoRepository inverterRepository, BoosterStationInfoRepository boosterStationInfoRepository,
                              AGC_AVCInfoRepository agcAvcInfoRepository, CollectingPowerLineInfoRepository collectingPowerLineInfoRepository, SubsidiaryEquipmentInfoRepository subsidiaryEquipmentInfoRepository) {
    this.weatherStationInfoRepository = weatherStationInfoRepository;
    this.windTowerRepository = windTowerRepository;
    this.windTurbineRepository = windTurbineRepository;
    this.inverterRepository = inverterRepository;
    this.boosterStationInfoRepository = boosterStationInfoRepository;
    this.agcAvcInfoRepository = agcAvcInfoRepository;
    this.collectingPowerLineInfoRepository = collectingPowerLineInfoRepository;
    this.subsidiaryEquipmentInfoRepository = subsidiaryEquipmentInfoRepository;
  }

  public List<AbstractEquipmentInfo> getAllEquipmentInfo() {
    List<AbstractEquipmentInfo> equipmentInfos = new ArrayList<>();
    equipmentInfos.addAll(weatherStationInfoRepository.findAll());
    equipmentInfos.addAll(windTowerRepository.findAll());
    equipmentInfos.addAll(windTurbineRepository.findAll());
    equipmentInfos.addAll(inverterRepository.findAll());
    equipmentInfos.addAll(agcAvcInfoRepository.findAll());
    equipmentInfos.addAll(boosterStationInfoRepository.findAll());
    equipmentInfos.addAll(collectingPowerLineInfoRepository.findAll());
    equipmentInfos.addAll(subsidiaryEquipmentInfoRepository.findAll());
    return equipmentInfos;
  }

  public List<AbstractEquipmentInfo> findByEqType(EquipmentTypeEnum eqType) {
    List<AbstractEquipmentInfo> equipmentInfos = new ArrayList<>();
    switch (eqType) {
      case WEATHERSTATION:
        equipmentInfos.addAll(weatherStationInfoRepository.findAll());
        break;
      case INVERTER:
        equipmentInfos.addAll(inverterRepository.findAll());
        break;
      case WINDTOWER:
        equipmentInfos.addAll(windTowerRepository.findAll());
        break;
      case WINDTURBINE:
        equipmentInfos.addAll(windTurbineRepository.findAll());
        break;
      case BOOSTERSTATION:
        equipmentInfos.addAll(boosterStationInfoRepository.findAll());
        break;
      case AGC_AVC:
        equipmentInfos.addAll(agcAvcInfoRepository.findAll());
        break;
      default:
        equipmentInfos.addAll(subsidiaryEquipmentInfoRepository.findSubsidiaryEquipmentInfosByEquipmentType(eqType));
    }
    return equipmentInfos;
  }
}
