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

import com.gyee.wisdom.common.data.DataUtil;
import com.gyee.wisdom.common.data.alarm.WindturbineTestingpointDi;
import com.gyee.wisdom.dao.alarm.WindturbinetestingpointDiDao;
import com.gyee.wisdom.dao.sql.alarm.Entity.WindturbineTestingpointDiEntity;
import com.gyee.wisdom.dao.sql.alarm.repository.WindturbinetestingpointDiRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
@Component
public class JpaWindturbinetestingpointDiDao implements WindturbinetestingpointDiDao {
    @Autowired
    private WindturbinetestingpointDiRepository windturbinetestingpointDiRepository;
    @Override
    public List<WindturbineTestingpointDi> findAll() {
        List<WindturbineTestingpointDi> windturbinetestingpointDiEntityList= DataUtil.convertDataList(windturbinetestingpointDiRepository.findAll());
        return windturbinetestingpointDiEntityList;
    }

    @Override
    public WindturbineTestingpointDi findById(String id) {
        WindturbineTestingpointDi windturbineTestingpointDi=windturbinetestingpointDiRepository.findById(id).get().toData();
        return windturbineTestingpointDi;
    }

    @Override
    public List<WindturbineTestingpointDi> getAllWindturbinetestingpointDiByWindpowerstationId(String windpowerstationid) {
        return  DataUtil.convertDataList(windturbinetestingpointDiRepository.getAllWindturbinetestingpointDiByWindpowerstationId(windpowerstationid));
    }

    @Override
    public List<WindturbineTestingpointDi> findByUniformcode(String id) {
        List<WindturbineTestingpointDiEntity> windturbineTestingpointDiEntityList = windturbinetestingpointDiRepository.findByUniformcode(id);
        List<WindturbineTestingpointDi> windturbineTestingpointDiList =new ArrayList<>();
        for(WindturbineTestingpointDiEntity windturbineTestingpointDiEntity:windturbineTestingpointDiEntityList){
            windturbineTestingpointDiList.add(windturbineTestingpointDiEntity.toData());
        }
        return windturbineTestingpointDiList;
    }

    @Override
    public void deletebyid(String id) {
        windturbinetestingpointDiRepository.deleteById(id);
    }


    @Override
    public void save(WindturbineTestingpointDi warning) {
        windturbinetestingpointDiRepository.save(new WindturbineTestingpointDiEntity(warning));
    }

    @Override
    public WindturbineTestingpointDi findByprojectId(String id) {
        return windturbinetestingpointDiRepository.findAllById(id).toData();
    }

}
