package com.izouma.dingdong.repo.merchant;

import com.izouma.dingdong.domain.merchant.MerchantClassification;
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;

public interface MerchantClassificationRepo extends JpaRepository<MerchantClassification, Long>, JpaSpecificationExecutor<MerchantClassification> {
    List<MerchantClassification> findAllByMerchantId(Long merchantId);

    //List<MerchantClassification> findAllByUserId(Long userId);

    MerchantClassification findByMerchantIdAndName(Long merchantId, String Name);

    //MerchantClassification findByUserIdAndName(Long merchantId, String Name);

    MerchantClassification findByMerchantIdAndType(Long merchantId, Integer type);

    @Query("update MerchantClassification t set t.enabled = false where t.id = ?1")
    @Modifying
    @Transactional
    void deleteById(Long id);

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

}