package com.example.cattletends.repository;

import com.example.cattletends.entity.CattleBreed;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * 品种表Repository
 */
@Repository
public interface CattleBreedRepository extends JpaRepository<CattleBreed, Integer> {
    
    /**
     * 根据品种名称查询
     */
    Optional<CattleBreed> findByBreedName(String breedName);
    
    /**
     * 检查品种名称是否存在
     */
    boolean existsByBreedName(String breedName);
    
    /**
     * 查询所有未删除的品种（is_delet=0）
     */
    @Query("SELECT b FROM CattleBreed b WHERE b.isDelet = 0 OR b.isDelet IS NULL")
    List<CattleBreed> findAllNotDeleted();
}

