package ba.unsa.etf.si.bbqms.repository;

import jakarta.persistence.EntityNotFoundException;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.NoRepositoryBean;

@NoRepositoryBean
public interface BaseRepository<T, ID> extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> {
    default T get(final ID id) {
        return findById(id).orElseThrow(() -> new EntityNotFoundException("Entity not found with id: " + id));
    }

    default T get(final Specification<T> specification) {
        return findOne(specification).orElseThrow(() -> new EntityNotFoundException("Entity not found"));
    }
}
