package com.izouma.dingdong.contorller;

import com.izouma.dingdong.domain.backstage.Category;
import com.izouma.dingdong.domain.merchant.Goods;
import com.izouma.dingdong.dto.MerchantDTO;
import com.izouma.dingdong.repo.merchant.MerchantRepo;
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 OrderInfoController {
    @Autowired
    private AuthenticationController auth;
    @Autowired
    private CategoryController categoryController;
    @Autowired
    private GoodsController goodsController;

    @Autowired
    private MerchantRepo merchantRepo;


    //商家注册
    @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()
                .address("测试测试")
                .aliAccount("11111")
                .aliName("测试")
                .logo("https://idingdong.oss-cn-hangzhou.aliyuncs.com/image/2020-05-14-10-01-57oAziBRXO.jpg")
                .category(categories)
                .endTime(LocalTime.parse("16:00:00"))
                .startTime(LocalTime.parse("14:00:00"))
                .merchantNatureId(1L)
                .phone("22222222")
                .password("22222222")
                .week("MONDAY,TUESDAY,WEDNESDAY")
                .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);
    }
}
