package com.njzscloud.supervisory.goods.controller;

import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.supervisory.goods.pojo.entity.GoodsCategoryEntity;
import com.njzscloud.supervisory.goods.service.GoodsCategoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品类型
 */
@Slf4j
@RestController
@RequestMapping("/goods_category")
@RequiredArgsConstructor
public class GoodsCategoryController {

    private final GoodsCategoryService goodsCategoryService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody GoodsCategoryEntity goodsCategoryEntity) {
        goodsCategoryService.add(goodsCategoryEntity);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody GoodsCategoryEntity goodsCategoryEntity) {
        goodsCategoryService.modify(goodsCategoryEntity);
        return R.success();
    }

    /**
     * 删除
     */
    @PostMapping("/del")
    public R<?> del(@RequestBody List<Long> ids) {
        goodsCategoryService.del(ids);
        return R.success();
    }

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<GoodsCategoryEntity> detail(@RequestParam Long id) {
        return R.success(goodsCategoryService.detail(id));
    }

    /**
     * 启用/禁用
     */
    @GetMapping("/enable")
    public R<?> enable(@RequestParam Long id, @RequestParam Boolean enable) {
        goodsCategoryService.enable(id, enable);
        return R.success();
    }

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<GoodsCategoryEntity>> paging(PageParam pageParam, GoodsCategoryEntity goodsCategoryEntity) {
        return R.success(goodsCategoryService.paging(pageParam, goodsCategoryEntity));
    }

}
