package com.fzm.mall.server.front.goods.controller;


import com.alibaba.fastjson.JSONObject;
import com.fzm.mall.server.front.base.ResponseVO;
import com.fzm.mall.server.front.constant.MallResponseEnum;
import com.fzm.mall.server.front.goods.model.Banner;
import com.fzm.mall.server.front.goods.model.Category;
import com.fzm.mall.server.front.goods.model.vo.testVo;
import com.fzm.mall.server.front.goods.service.ICategoryService;
import io.netty.util.internal.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 商品类别 前端控制器
 * </p>
 *
 * @author fzm
 * @since 2021-03-02
 */
@Api("商品模块")
@RestController
@RequestMapping("/mall/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    @ApiOperation(value = "获取类目(参数：categoryId 为“”就是一级目录)")
    @PostMapping("/without/getCategory")
    public ResponseVO<List<Category>> getCategory(@RequestBody JSONObject data){
//    public ResponseVO<List<Category>> getCategory(@RequestParam String categoryId){
        String categoryId = data.getString("categoryId");
        System.out.println(categoryId);
        List<Category> categories = new ArrayList<>();
        if(StringUtil.isNullOrEmpty(categoryId)){
            categories = categoryService.getList();
        }else{
            categories = categoryService.getList(categoryId);
        }

        return new ResponseVO<List<Category>>(MallResponseEnum.SUCCESS,categories);
    }

    /*@ApiOperation(value = "根据父类目查下面子类目")
    @PostMapping("/without/getChildCategory")
    public ResponseVO<List<Category>> getCategory(@RequestBody JSONObject data){
//    public ResponseVO<List<Category>> getCategory(@RequestParam String categoryId){
        String categoryId = data.getString("categoryId");
        System.out.println(categoryId);
        List<Category> categories = new ArrayList<>();
        if(StringUtil.isNullOrEmpty(categoryId)){
            categories = categoryService.getList();
        }else{
            categories = categoryService.getList(categoryId);
        }

        return new ResponseVO<List<Category>>(MallResponseEnum.SUCCESS,categories);
    }*/

}
