package com.izouma.dingdong.repo.merchant;

import com.izouma.dingdong.domain.backstage.Category;
import com.izouma.dingdong.domain.merchant.MerchantSettings;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;

public interface MerchantSettingsRepo extends JpaRepository<MerchantSettings, Long>, JpaSpecificationExecutor<MerchantSettings> {
    @Query("update MerchantSettings t set t.enabled = false where t.id = ?1")
    @Modifying
    @Transactional
    void deleteById(Long id);

    Optional<MerchantSettings> findByMerchantId(Long merchantId);

    @Query("update MerchantSettings t set t.enabled = false where t.merchantId = ?1")
    @Modifying
    @Transactional
    void deleteByMerchantId(Long merchantId);

    //按分类显示商家
    List<MerchantSettings> findAllByCategoryContains(Category category);

}