package com.izouma.dingdong.repo;

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

public interface AppraisalRepo extends JpaRepository<Appraisal, Long>, JpaSpecificationExecutor<Appraisal> {

    Optional<Appraisal> findByOrderInfoId(Long orderId);

    List<Appraisal> findAllByMerchantId(Long merchantId);

    List<Appraisal> findAllByRiderId(Long riderId);

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

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


}