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

import com.gyee.wisdom.common.data.DataUtil;
import com.gyee.wisdom.common.data.windturbine.EquipmentModel;
import com.gyee.wisdom.dao.windturbine.IModelDao;
import com.gyee.wisdom.dao.sql.Windturbine.entity.ModelEntity;
import com.gyee.wisdom.dao.sql.Windturbine.repsoitory.ModelRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class JpaModelDao implements IModelDao
{
    @Autowired
    private ModelRepository modelRepository;


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

    @Override
    public EquipmentModel findById(String id) {
        return modelRepository.findById(id).get().toData();
    }

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

    @Override
    public void save(EquipmentModel equipmentModel) {
        modelRepository.save(new ModelEntity(equipmentModel));
    }

}
