package com.izouma.immall.repo;

import com.izouma.immall.domain.BackUser;
import com.izouma.immall.security.Authority;
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 BackUserRepo extends JpaRepository<BackUser, Long>, JpaSpecificationExecutor<BackUser> {

    BackUser findByUsername(String username);

    List<BackUser> findAllByAuthoritiesContains(Authority authority);

//    BackUser findByOpenId(String openId);

    BackUser findByPhone(String phone);

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


}
