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


import com.gyee.wisdom.common.data.DataUtil;
import com.gyee.wisdom.common.data.alarm.Warning;
import com.gyee.wisdom.common.data.alarm.WarningClassify;
import com.gyee.wisdom.dao.alarm.WarningDao;
import com.gyee.wisdom.dao.sql.alarm.Entity.WarningEntity;
import com.gyee.wisdom.dao.sql.alarm.repository.WarningClassifyRepository;
import com.gyee.wisdom.dao.sql.alarm.repository.WarningRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import java.util.List;

@Component
public class JpaWarningDao implements WarningDao {
    @Autowired
    private WarningRepository warningRepository;

    @Autowired
    private WarningClassifyRepository warningClassifyRepository;

    @Override
    public List<WarningClassify> findAllWarningClassify() {
        return DataUtil.convertDataList(warningClassifyRepository.findAll());
    }

    @Override
    public List<Warning> findAll() {
        List<Warning> warning = DataUtil.convertDataList(warningRepository.findAll());
        return warning;
    }

    @Override
    public Warning findById(String id) {
        Warning warning = warningRepository.findById(id).get().toData();
        return warning;
    }

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


    @Override
    public void save(Warning warning) {
        warningRepository.save(new WarningEntity(warning));
    }

    @Override
    public Warning findByprojectId(String id) {
        return warningRepository.findAllById(id).toData();
    }

    @Override
    public Warning findByEdnavalue(int ednavalue) {
        return warningRepository.findByEdnaValue(ednavalue).toData();
    }

    @Override
    public List<Warning> findByModelId(String modelid) {
        return DataUtil.convertDataList(warningRepository.findByModelId(modelid));
    }
    @Override
    public List<Warning> findByModelIdIn(String[] modelids) {
        return DataUtil.convertDataList(warningRepository.findByModelIdIn(modelids));
    }

    @Override
    public List<Warning> findByIsReset(Integer isReset) {
        return DataUtil.convertDataList(warningRepository.findByIsReset(isReset));
    }
}
