package fyloz.trial.ColorRecipesExplorer.services;

import fyloz.trial.ColorRecipesExplorer.dao.MaterialTypeDao;
import fyloz.trial.ColorRecipesExplorer.model.MaterialType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MaterialTypeService extends GenericService<MaterialType> {

    private MaterialTypeDao materialTypeDao;

    @Autowired
    public MaterialTypeService(MaterialTypeDao materialTypeDao) {
        super(materialTypeDao);
        this.materialTypeDao = materialTypeDao;
    }

    @Override
    public boolean isValidForCreation(MaterialType entity) {
        return entity != null && !existsByName(entity);
    }

    public boolean existsByName(MaterialType entity) {
        return materialTypeDao.findByMaterialTypeName(entity.getMaterialTypeName()) != null;
    }
}
