package com.gree.mall.manager.controller.goods;

import com.gree.mall.manager.bean.goods.GoodsCategoryBean;
import com.gree.mall.manager.exception.RemoteServiceException;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.goods.GoodsCategoryLogic;
import com.gree.mall.manager.plus.entity.CarouselMap;
import com.gree.mall.manager.plus.entity.GoodsCategory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@Api(value = "分类管理", tags ={"分类管理"} )
@RequestMapping(value = "/goods/category", produces = "application/json; charset=utf-8")
public class GoodsCategoryController {

    @Resource
    GoodsCategoryLogic goodsCategoryLogic;

    @GetMapping("/list")
    @ApiOperation(value = "分类管理列表")
    public ResponseHelper<List<GoodsCategoryBean>> page(
            @RequestParam(required = false)Integer type,
            @ApiParam(value = "层级",required = false) @RequestParam(required = false, defaultValue = "1") Integer categoryLevel,
            @ApiParam(value = "分类名称",required = false) @RequestParam(required = false) String name,
            @ApiParam(value = "状态(true：显示 false:隐藏",required = false) @RequestParam(required = false) Boolean status,
            HttpServletRequest request
    ) throws RemoteServiceException {
        List<GoodsCategoryBean> list = goodsCategoryLogic.list(type,categoryLevel,name,status,request);
        return ResponseHelper.success(list);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增分类")
    public ResponseHelper add(
            @ApiParam(value = "object",required = true) @RequestBody GoodsCategoryBean goodsCategoryBean,HttpServletRequest request) {
        goodsCategoryLogic.add(goodsCategoryBean,request);
        return ResponseHelper.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改分类")
    public ResponseHelper update(
            @ApiParam(value = "object",required = true) @RequestBody GoodsCategory goodsCategory) {
        goodsCategoryLogic.update(goodsCategory);
        return ResponseHelper.success();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除分类")
    public ResponseHelper delete(
            @ApiParam(value = "分类id",required = true) @RequestParam String categoryId
    ) {
        goodsCategoryLogic.delete(categoryId);
        return ResponseHelper.success();
    }

    @GetMapping("/detail")
    @ApiOperation("详情")
    public ResponseHelper<GoodsCategory> detail(
            @ApiParam(value = "分类id",required = true) @RequestParam String categoryId
    ){
        GoodsCategory detail = goodsCategoryLogic.detail(categoryId);
        return ResponseHelper.success(detail);
    }
}
