package com.lanyuanxiaoyao.leopard.core.repository;

import com.lanyuanxiaoyao.leopard.core.entity.Stock;
import com.lanyuanxiaoyao.service.template.repository.SimpleRepository;
import jakarta.transaction.Transactional;
import java.util.Collection;
import java.util.List;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * @author lanyuanxiaoyao
 * @version 20250828
 */
@Repository
public interface StockRepository extends SimpleRepository<Stock> {
  @Query("select distinct stock.industry from Stock stock where stock.industry is not null")
  List<String> findDistinctIndustries();

  @Query("select distinct stock.code from Stock stock")
  List<String> findDistinctCodes();

  @Modifying
  @Transactional(rollbackOn = Throwable.class)
  void deleteAllByCodeIn(Collection<String> code);

  @EntityGraph(attributePaths = {"indicators"})
  @Query("from Stock stock where size(stock.indicators) >= ?1")
  List<Stock> findAllByIndicatorsSizeGreaterThanEqual(int count);
}
