package com.izouma.immall.repo;

import com.izouma.immall.domain.VipUser;
import com.izouma.immall.enums.VipType;
import com.izouma.immall.security.VipAuthority;
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.time.LocalDateTime;
import java.util.List;

public interface VipUserRepo extends JpaRepository<VipUser, Long>, JpaSpecificationExecutor<VipUser> {
    List<VipUser> findAllByUserId(Long userId);

//    List<VipUser> findAllByVipAuthoritiesContains(VipAuthority vipAuthority);

//    List<VipUser> findAllByStartTime(LocalDateTime startTime);

    List<VipUser> findAllByVipType(VipType vipType);

    List<VipUser> findByOpenId(String OpenId);

//    void saveByUserId(String userId);

//    List<VipUser> findAllByStartTimeBetweenEndTime(LocalDateTime startTime, LocalDateTime endTime);

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

    List<VipUser> findAllByUserIdAndEnabledFalse(Long userId);

    List<VipUser> findAllByOpenIdAndEnabledFalse(String openId);
}
