package com.pharmacopoeia.repository;

import com.pharmacopoeia.entity.QuickAsk;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface QuickAskRepository extends JpaRepository<QuickAsk, Integer> {

    List<QuickAsk> findAllByOrderBySortOrderAscIdAsc();

    List<QuickAsk> findByIsActiveTrueOrderBySortOrderAscIdAsc();

    long countByLabel(String label);

    long countByLabelAndIdNot(String label, Integer id);

    @Modifying
    @Transactional
    @Query("UPDATE QuickAsk q SET q.sortOrder = :sortOrder, q.updatedBy = :updatedBy WHERE q.id = :id")
    int updateSortOrder(@Param("id") Integer id, @Param("sortOrder") Integer sortOrder, @Param("updatedBy") String updatedBy);
}
