package com.gyee.wisdom.dataadapter.domain.thing;
import com.gyee.wisdom.common.data.windturbine.Line;
import com.gyee.wisdom.common.data.windturbine.PowerStation;
import com.gyee.wisdom.common.data.windturbine.Project;
import com.gyee.wisdom.common.data.windturbine.Windturbine;
import com.gyee.wisdom.dao.windturbine.ILineDao;
import com.gyee.wisdom.dao.windturbine.IPowerStationDao;
import com.gyee.wisdom.dao.windturbine.IProjectDao;
import com.gyee.wisdom.dao.windturbine.IWindturbineDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProjectService {

    @Autowired
    protected IProjectDao jpaprojectDao;
    @Autowired
    protected IWindturbineDao jpawindturbineDao;
    @Autowired
    protected ILineDao jpalineDao;
    @Autowired
    protected IPowerStationDao jpapowerstationDao;

    public List<Project> findAll() {
        return jpaprojectDao.findAll();
    }

    public Project findById(String id) {
        return jpaprojectDao.findbyid(id);
    }

    public void save(Project project) {
        jpaprojectDao.save(project);
    }

    public void delete(String id) {
        jpaprojectDao.delete(id);
    }

    public List<Project> findbystationId(String stationId) {
        return jpaprojectDao.findbyStationId(stationId);
    }

    public Map<String, Map<String, String>> getProjectmap() {
        Map<String, Map<String, String>> projectmap = new HashMap<>();
        List<PowerStation> powerStationlist = jpapowerstationDao.getAll();
        for (PowerStation pj : powerStationlist) {
            Map<String, String> map = new HashMap<>();
            projectmap.put(pj.getId(), map);
        }

        List<Project> projectlist = jpaprojectDao.findAll();
        for(Project project:projectlist){
            projectmap.get(project.getStationId()).put(project.getId(),project.getName());
        }
            return projectmap;
        }


    public Map<String, Map<String, String>> getLinemap() {
        Map<String, Map<String, String>> linemap = new HashMap<>();
        List<Project> projectlist = jpaprojectDao.findAll();
        for (Project pj : projectlist) {
            Map<String, String> map = new HashMap<>();
            linemap.put(pj.getId(), map);
        }

        List<Line> linelist = jpalineDao.findAll();
        for(Line line:linelist){
            linemap.get(line.getProjectId()).put(line.getId(),line.getName());
        }
        return linemap;
    }


    public Map<String, Map<String, String>> getWinturbinemap() {
        Map<String, Map<String, String>> windturbinemap = new HashMap<>();
        List<Line> linelist = jpalineDao.findAll();
        for (Line ln : linelist) {
            Map<String, String> map = new HashMap<>();
            windturbinemap.put(ln.getId(), map);
        }

        List<Windturbine> windturbinelist = jpawindturbineDao.find();
        for(Windturbine windturbine:windturbinelist){
            windturbinemap.get(windturbine.getModelId()).put(windturbine.getId(),windturbine.getName());
        }
        return windturbinemap;
    }


}
