package com.izouma.dingdong.service;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.izouma.dingdong.domain.OrderGoodsSpec;
import com.izouma.dingdong.domain.user.ShoppingCart;
import com.izouma.dingdong.exception.BusinessException;
import com.izouma.dingdong.repo.OrderGoodsSpecRepo;
import com.izouma.dingdong.repo.user.ShoppingCartRepo;
import com.izouma.dingdong.service.user.ShoppingCartService;
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.test.context.junit4.SpringRunner;

import java.util.List;

@SpringBootTest
@RunWith(SpringRunner.class)
public class ShoppingCartServiceTest {

    @Autowired
    private ShoppingCartService   shoppingCartService;
    @Autowired
    private ShoppingCartRepo      shoppingCartRepo;
    @Autowired
    private OrderGoodsSpecService orderGoodsSpecService;


    @Test
    public void testCart() {
        OrderGoodsSpec add = orderGoodsSpecService.add(1258L, null, 1);

        // OrderGoodsSpec add = orderGoodsSpecRepo.findById(1318L).orElse(null);

        //System.out.println(shoppingCartService.save(83L, add));
    }

    @Test
    public void test() {
        System.out.println(shoppingCartRepo.findById(1484L).orElse(null));
    }

    @Test
    public void testSub() {
        OrderGoodsSpec add = orderGoodsSpecService.add(1636L, null, 1);
        System.out.println(shoppingCartService.add(82L, add, 1.0, 1.0));
        //System.out.println(shoppingCartService.sub(1500L, 83L));
    }

    @Test
    public void testFalse() {
        //System.out.println(shoppingCartRepo.findByIdAndEnabledIsFalse(1759L));

        System.out.println(shoppingCartRepo.findById(1759L).orElse(null));
    }

    @Test
    public void testAgain() {
        System.out.println(shoppingCartService.again(1729L,1.0,1.0));
    }

    @Test
    public void testMyMer() {
        ShoppingCart cart = shoppingCartRepo.findByUserIdAndMerchantId(82L, 927L);
        if (ObjectUtil.isEmpty(cart)) {
            System.out.println("null");
        } else {
            List<OrderGoodsSpec> specs = cart.getOrderGoodsSpecs();
            System.out.println(specs);
        }
    }

    @Test
    public void testNum() {
        shoppingCartService.changeNum(1808L, 10);
    }
}
