package com.wzj.soopin.goods.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.goods.convert.ProductCategoryConvert;
import com.wzj.soopin.goods.domain.bo.ProductCategoryBo;
import com.wzj.soopin.goods.domain.entity.ProductCategory;
import com.wzj.soopin.goods.domain.vo.ProductCategoryVO;
import com.wzj.soopin.goods.service.impl.ProductCategoryServiceImpl;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 商品分类Controller
 *
 * @author zcc
 * @date 2022-11-28
 */
@Tag(name ="商品分类接口列表")
@RestController
@RequestMapping("/pms/product/category")
@RequiredArgsConstructor
public class ProductCategoryController extends BaseController {



    private final ProductCategoryServiceImpl service;
    private final ProductCategoryConvert convert;

    @Tag(name = "查询列表")
    @PostMapping("/tree")
    public R< List<ProductCategoryVO>> tree(@RequestBody ProductCategoryBo bo ) {
        List<ProductCategoryVO> articleList = service.tree( bo.toWrapper());
        return R.ok( articleList);
    }
    @Tag(name = "查询列表")
    @PostMapping("/page")
    public R<IPage<ProductCategoryVO>> page(@RequestBody ProductCategoryBo bo, @RequestBody Page page) {
        Page<ProductCategory> pages = service.page(page, bo.toWrapper());
        return R.ok(convert.toVO(pages));
    }
    @Tag(name ="查询商品分类列表")
    @PostMapping("list")
    public R<List<ProductCategoryVO>> list(@RequestBody ProductCategoryBo query) {
        List<ProductCategory> productCategoryList = service.list(query.toWrapper());
        return R.ok(convert.toVO(productCategoryList));
    }

    @Tag(name ="获取商品分类详细信息")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id) {
        return R.ok(service.getById(id));
    }

    @Tag(name ="获取商品分类详细信息")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@RequestBody ProductCategory productCategory) {
        return R.ok(service.save(productCategory));
    }

    @Tag(name ="修改商品分类")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R edit(@RequestBody ProductCategory productCategory) {
        return R.ok(service.updateById(productCategory));
    }

    @Tag(name ="删除商品分类")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public R remove(@PathVariable Long id) {
        return R.ok(service.removeById(id));
    }


}
