package com.izouma.dingdong.contorller;

import com.izouma.dingdong.domain.backstage.Category;
import com.izouma.dingdong.domain.backstage.MerchantNature;
import com.izouma.dingdong.domain.merchant.Goods;
import com.izouma.dingdong.dto.MerchantDTO;
import com.izouma.dingdong.dto.UserOrderDTO;
import com.izouma.dingdong.enums.PayMethod;
import com.izouma.dingdong.repo.backstage.MerchantNatureRepo;
import com.izouma.dingdong.repo.merchant.MerchantRepo;
import com.izouma.dingdong.service.OrderInfoService;
import com.izouma.dingdong.web.AuthenticationController;
import com.izouma.dingdong.web.backstage.CategoryController;
import com.izouma.dingdong.web.merchant.GoodsController;
import com.izouma.dingdong.web.merchant.MerchantClassificationController;
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.math.BigDecimal;
import java.time.LocalTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@RunWith(SpringRunner.class)
@SpringBootTest
public class OrderInfoControllerTest {
    @Autowired
    private AuthenticationController auth;
    @Autowired
    private CategoryController categoryController;
    @Autowired
    private GoodsController goodsController;
    @Autowired
    private MerchantRepo merchantRepo;
    @Autowired
    private OrderInfoService orderInfoService;
    @Autowired
    private MerchantNatureRepo merchantNatureRepo;

    //商家注册
    @Test
    public void testMerReg() {
//        Set<Category> categories = new HashSet<>();
//        List<Category> tree = categoryController.tree(137L);
//        //System.out.println(tree);
//        categories.add(tree.get(0));

        MerchantDTO merchantDTO = MerchantDTO.builder()
                .name("测试的店店店")
                .showName("测试的店店店")
                .phone("12")
                .password("123")
                .qualification("https%3A%2F%2Fidingdong.oss-cn-hangzhou.aliyuncs.com%2Fimage%2F2020-06-10-17-11-42qXdpsfqA.png%2Chttps%3A%2F%2Fidingdong.oss-cn-hangzhou.aliyuncs.com%2Fimage%2F2020-06-10-17-11-45pluNBzOF.png")
                .doorHeadImg("https%3A%2F%2Fidingdong.oss-cn-hangzhou.aliyuncs.com%2Fimage%2F2020-06-10-17-11-52kTVlWTJi.png&img=https%3A%2F%2Fidingdong.oss-cn-hangzhou.aliyuncs.com%2Fimage%2F2020-06-10-17-11-55CJthQhYR.png")
                .categoryId("139")
                .address("1")
                .week("MONDAY%2CTUESDAY%2CWEDNESDAY%2CTHURSDAY%2CFRIDAY%2CSATURDAY%2CSUNDAY")
                .startTime(LocalTime.parse("08:00:00"))
                .endTime(LocalTime.parse("23:00:00"))
                .merchantNatureId(2L)
                .logo("https%3A%2F%2Fidingdong.oss-cn-hangzhou.aliyuncs.com%2Fimage%2F2020-06-10-17-12-47SkeOftcH.png")
                //.aliAccount("131456")
                //.aliName("小爽")
                //.category(categories)
               // .automaticOrder(true)
                //.startingAmount(BigDecimal.valueOf(20))
                //.banner("https://idingdong.oss-cn-hangzhou.aliyuncs.com/image/2020-05-14-10-01-57oAziBRXO.jpg")
                //.introduction("最可爱的小爽开的店")
                .build();

        System.out.println(auth.registerMerchant(merchantDTO));
    }

    //注册添加商品
    @Test
    public void testGoods() {
        Goods goods = Goods.builder()
                .amount(BigDecimal.valueOf(111))
                .discountAmount(BigDecimal.valueOf(111))
                .endTime(LocalTime.parse("20:00:00"))
                .startTime(LocalTime.parse("05:00:00"))
                .merchantId(356L)
                .name("111")
                .packingPrice(BigDecimal.valueOf(10))
                .inventory(1)
                .week("MON,THU")
                .img("https://idingdong.oss-cn-hangzhou.aliyuncs.com/image/2020-05-18-13-44-55zltwyJVa.png")
                //.discountAmount(BigDecimal.valueOf(188))
                .build();
        System.out.println(goodsController.save(goods));
    }

    @Test
    public void testClass() {
        System.out.println(merchantRepo.findById(357L).orElse(null));
    }

    @Test
    public void goodsPass() {
        goodsController.audit(319L, true, null);
    }

    @Test
    public void testMy(){
        System.out.println(orderInfoService.my(83L));
    }

    @Test
    public void testBuy(){
        UserOrderDTO dto = UserOrderDTO.builder()
                .addressId(135L)
                .payMethod(PayMethod.ALI_PAY)
                .shoppingCartId(1704L)
                //.remark("多加点！")
                //.userCouponId(217L)
                .build();

        System.out.println(orderInfoService.userOrder(dto).getId());
    }

    @Test
    public void testMer(){
        orderInfoService.merReceiveOrder(1352L,true);
    }
}
