package com.mosquito.project.persistence.repository;

import com.mosquito.project.persistence.entity.SystemConfigEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

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

public interface SystemConfigRepository extends JpaRepository<SystemConfigEntity, Long> {

    Optional<SystemConfigEntity> findByConfigKey(String configKey);

    List<SystemConfigEntity> findByCategory(String category);

    @Query("SELECT c FROM SystemConfigEntity c WHERE " +
           "(:category IS NULL OR c.category = :category) AND " +
           "(:keyword IS NULL OR c.configKey LIKE %:keyword% OR c.configValue LIKE %:keyword%)")
    List<SystemConfigEntity> findByFilters(@Param("category") String category, @Param("keyword") String keyword);
}
