package com.zfire.mall.manager.controller.manage.product.category;

import com.zfire.mall.manager.bean.manage.product.category.ProductCategoryBean;
import com.zfire.mall.manager.bean.manage.product.category.ProductCategoryRelaBean;
import com.zfire.mall.manager.bean.valid.EditGroup;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.manage.product.category.ProductCategoryLogic;
import com.zfire.mall.manager.plus.entity.KingDeeCategory;
import com.zfire.mall.manager.plus.entity.ProductCategory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.groups.Default;
import java.util.List;

@Slf4j
@RestController
@Api(value = "存货类别", tags ={"存货类别"} )
@RequestMapping(value = "/product-category", produces = "application/json; charset=utf-8")
public class ProductCategoryController {

    @Resource
    ProductCategoryLogic productCategoryLogic;

    @ApiOperation(value = "产品品类列表")
    @GetMapping("/list")
    public ResponseHelper<List<ProductCategory>> list(
            @ApiParam(value = "产品品类编码") @RequestParam(required = false) String productCategoryNumber,
            @ApiParam(value = "产品品类名称") @RequestParam(required = false)  String productCategoryName
    ) throws Exception {
        List<ProductCategory> list = productCategoryLogic.allList(productCategoryNumber, productCategoryName);
        return ResponseHelper.success(list);
    }

    @ApiOperation(value = "产品品类详情")
    @PostMapping("/detail")
    public ResponseHelper<ProductCategory> detail(
            @ApiParam(value = "产品品类id", required = true) @RequestParam String id) throws Exception {
        ProductCategory productCategory = productCategoryLogic.detail(id);
        return ResponseHelper.success(productCategory);
    }

    @ApiOperation(value = "产品品类小类列表")
    @GetMapping("/sub-list")
    public ResponseHelper<List<ProductCategoryRelaBean>> subList(
            @ApiParam(value = "产品品类id", required = true) @RequestParam String id
    ) throws Exception {
        List<ProductCategoryRelaBean> list = productCategoryLogic.subList(id);
        return ResponseHelper.success(list);
    }

    @ApiOperation(value = "金蝶存货类别列表")
    @GetMapping("/king-dee-category-list")
    public ResponseHelper<List<ProductCategoryRelaBean>> kingDeeCategoryList() throws Exception {
        List<KingDeeCategory> list = productCategoryLogic.kingDeeCategoryList();
        return ResponseHelper.success(list);
    }



    @ApiOperation(value = "金蝶存货类别列表")
    @GetMapping("/king-dee-category")
    public ResponseHelper<List<ProductCategoryRelaBean>> kingDeeCategory() throws Exception {
        List<KingDeeCategory> list = productCategoryLogic.kingDeeCategory();
        return ResponseHelper.success(list);
    }


    @ApiOperation(value = "新增产品品类")
    @PostMapping("/add")
    public ResponseHelper add(
            @ApiParam(required = true, value = "产品品类") @RequestBody @Validated ProductCategoryBean productCategoryBean
    ) throws Exception {
        return ResponseHelper.success(productCategoryLogic.add(productCategoryBean));
    }

    @ApiOperation(value = "新增产品品类小类")
    @PostMapping("/add-sub")
    public ResponseHelper addSub(
            @ApiParam(required = true, value = "产品品类") @RequestBody @Validated ProductCategoryBean productCategoryBean
    ) throws Exception {
        productCategoryLogic.addSub(productCategoryBean);
        return ResponseHelper.success();
    }

    @ApiOperation(value = "编辑产品品类")
    @PostMapping("/edit")
    public ResponseHelper edit(
            @ApiParam(required = true, value = "产品品类") @Validated(value = { EditGroup.class, Default.class }) @RequestBody ProductCategoryBean productCategoryBean
    ) throws Exception {
        productCategoryLogic.edit(productCategoryBean);
        return ResponseHelper.success();
    }

    @ApiOperation(value = "删除产品品类小类")
    @PostMapping("/del-sub")
    public ResponseHelper delSub(
            @ApiParam(required = true, value = "产品品类小类id") @RequestParam List<String> ids
    ) throws Exception {
        productCategoryLogic.delSub(ids);
        return ResponseHelper.success();
    }

    @ApiOperation(value = "删除产品品类")
    @PostMapping("/del")
    public ResponseHelper del(
            @ApiParam(required = true, value = "产品品类id") @RequestParam List<String> ids
    ) throws Exception {
        productCategoryLogic.del(ids);
        return ResponseHelper.success();
    }


}
