package com.izouma.dingdong.repo;


import com.izouma.dingdong.domain.OrderInfo;
import com.izouma.dingdong.dto.PageQuery;
import com.izouma.dingdong.enums.MerchantStatus;
import com.izouma.dingdong.enums.OrderStatus;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.test.context.junit4.SpringRunner;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import static com.izouma.dingdong.web.BaseController.*;


@RunWith(SpringRunner.class)
@SpringBootTest
public class OrderInfoRepoTest {
    @Autowired
    private OrderInfoRepo orderInfoRepo;

    @Test
    public void testOrder() {
        System.out.println(orderInfoRepo.sumRealAmountByUserId(170L));
    }

    @Test
    public void testTime() {
        System.out.println(orderInfoRepo.findAllByStatusAndOrderTimeAfterAndMerchantStatus(OrderStatus.PAID, LocalDateTime
                .now()
                .plusMinutes(5), MerchantStatus.RECEIVED));
    }

    @Test
    public void test1() {
//        System.out.println(orderInfoRepo.findAllByRiderIdIsNullAndMerchantStatus(MerchantStatus.RECEIVED));
        System.out.println(orderInfoRepo.findById(2085L).orElse(null));
    }


    @Test
    public void testMy() {
        PageQuery pageQuery = new PageQuery();
        Map<String, Object> map = new HashMap<>();
        map.put("merchantId", 189);
        map.put("merchantStatus", "NOT_RECEIVED");
        if ("NOT_RECEIVED".equals(map.get("merchantStatus"))){
            map.put("status","PAID");
        }
        pageQuery.setQuery(map);

        Page<Long> map1 = orderInfoRepo.findAll(toSpecification(pageQuery, OrderInfo.class), toPageRequest(pageQuery))
                .map(OrderInfo::getId);
        System.out.println(map1.getContent());
    }

}
