package com.izouma.jiashanxia.repo;

import com.izouma.jiashanxia.domain.OrderInfo;
import com.izouma.jiashanxia.enums.OrderInfoStatus;
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 OrderInfoRepo extends JpaRepository<OrderInfo, Long>, JpaSpecificationExecutor<OrderInfo> {
    @Query("update OrderInfo t set t.del = true where t.id = ?1")
    @Modifying
    @Transactional
    void softDelete(Long id);

    @Query(nativeQuery = true, value = "SELECT count(1) FROM order_info")
    int orderNum();

    long countByStatus(OrderInfoStatus status);

    List<OrderInfo> findAllByPaidAtBetweenAndStatus(LocalDateTime paidAt, LocalDateTime paidAt2, OrderInfoStatus status);

    long countByUserId(Long userId);
}