package com.gyee.wisdom.dao.sql.alarm;

import com.gyee.wisdom.common.data.DataUtil;
import com.gyee.wisdom.common.data.alarm.GyeeProject;
import com.gyee.wisdom.common.data.windturbine.Project;
import com.gyee.wisdom.dao.alarm.IGyeeProjectDao;
import com.gyee.wisdom.dao.sql.Windturbine.entity.ProjectEntity;
import com.gyee.wisdom.dao.sql.Windturbine.repsoitory.ProjectRepository;
import com.gyee.wisdom.dao.sql.alarm.Entity.GyeeProjectEntity;
import com.gyee.wisdom.dao.sql.alarm.repository.GyeeProjectRepository;
import com.gyee.wisdom.dao.windturbine.IProjectDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class JpaGyeeProjectDao implements IGyeeProjectDao {
    @Autowired
    private GyeeProjectRepository gyeeprojectRepository;

    @Override
    public void delete(String id) {
        gyeeprojectRepository.deleteById(id);
    }

    @Override
    public void save(GyeeProject project) {
        gyeeprojectRepository.save(new GyeeProjectEntity(project));
    }

    @Override
    public List<GyeeProject> findAll() {
        return DataUtil.convertDataList(gyeeprojectRepository.findAll());
    }

    @Override
    public GyeeProject findbyid(String id) {
        return gyeeprojectRepository.findById(id).get().toData();
    }

    @Override
    public List<GyeeProject> findbyStationId(String stationId) {
        List<GyeeProjectEntity> lpe=gyeeprojectRepository.findByStationIdEquals(stationId);
        return DataUtil.convertDataList(
                gyeeprojectRepository.findByStationIdEquals(stationId)
        );
    }
}
