package com.izouma.dingdong.repo.merchant;

import com.izouma.dingdong.domain.merchant.Merchant;
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;
import java.util.Optional;

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

    Merchant findByPhone(String phone);

    Optional<Merchant> findByUserId(Long userId);

    //按商户Id找出用户Id
    @Query("select t.userId from Merchant t where t.id = ?1")
    Long findUserIdById(Long id);

    List<Merchant> findAllByEstablishTimeAfter(LocalDateTime dateTime);

}