package com.izouma.nineth.repo;

import com.izouma.nineth.domain.PurchaseLevel;
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;

public interface PurchaseLevelRepo extends JpaRepository<PurchaseLevel, Long>, JpaSpecificationExecutor<PurchaseLevel> {
    @Query("update PurchaseLevel t set t.del = true where t.id = ?1")
    @Modifying
    @Transactional
    void softDelete(Long id);

    @Query(value = "select * from purchase_level a where a.start_level <= ?1 and a.end_level >= ?1 and a.del = 0",nativeQuery = true)
    PurchaseLevel findByLevel(int level);

    @Query(value = "select max(start_level) from purchase_level",nativeQuery = true)
    int findMaxStartLevel();

    PurchaseLevel findByStartLevel(int startLevel);
}