package com.gree.mall.miniapp.controller.trade;


import com.gree.mall.miniapp.bean.goods.GoodsCategoryBean;
import com.gree.mall.miniapp.bean.order.GoodsCategoryItemBean;
import com.gree.mall.miniapp.bean.order.OrderCategoryItem;
import com.gree.mall.miniapp.exception.RemoteServiceException;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.goods.GoodsCategoryLogic;
import com.gree.mall.miniapp.plus.entity.Goods;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;

@Slf4j
@RestController
@Api(value = "以旧换新配置", tags = {"以旧换新API"})
@RequestMapping(value = "/trade", produces = "application/json; charset=utf-8")
public class TradeController {



    @Autowired
    GoodsCategoryLogic goodsCategoryLogic;



    @GetMapping("/list")
    @ApiOperation(value = "一二级回收类别")
    public ResponseHelper<List<GoodsCategoryBean>> page(
            HttpServletRequest request
    ) throws RemoteServiceException {
        List<GoodsCategoryBean> list = goodsCategoryLogic.listGoodsCategory(request);
        return ResponseHelper.success(list);
    }


    @GetMapping("/listCategoryItem")
    @ApiOperation(value = "三级属性")
    public ResponseHelper<List<GoodsCategoryItemBean>> listCategoryItem(
            @ApiParam(value = "二级大类id",required = true) @RequestParam String mainId
    ) throws RemoteServiceException {
        List<GoodsCategoryItemBean> list = goodsCategoryLogic.listCategoryItem(mainId);
        return ResponseHelper.success(list);
    }


    @GetMapping("/orderCategoryItem")
    @ApiOperation(value = "传ids返回以旧换新")
    public ResponseHelper<OrderCategoryItem> orderCategoryItem(
            @ApiParam(value = "所选属性ids",required = true) @RequestParam List<String> ids
    ) throws RemoteServiceException {
        OrderCategoryItem orderCategoryItem = goodsCategoryLogic.orderCategoryItem(ids);
        return ResponseHelper.success(orderCategoryItem);
    }


    @GetMapping("/getMaxPrice")
    @ApiOperation(value = "拿到最高价格")
    public ResponseHelper<BigDecimal> getMaxPrice(
    ) throws RemoteServiceException {
        BigDecimal maxPrice = goodsCategoryLogic.getMaxPrice();
        return ResponseHelper.success(maxPrice);
    }

}
