package com.njzscloud.dispose.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.dispose.goods.pojo.param.AddGoodsParam;
import com.njzscloud.dispose.goods.pojo.param.ModifyGoodsParam;
import com.njzscloud.dispose.goods.pojo.param.SearchGoodsParam;
import com.njzscloud.dispose.goods.pojo.result.SearchGoodsResult;
import com.njzscloud.dispose.goods.service.GoodsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品
 *
 * @author ljw
 */
@Slf4j
@RestController
@RequestMapping("/goods")
@RequiredArgsConstructor
public class GoodsController {

    private final GoodsService goodsService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody AddGoodsParam addGoodsParam) {
        goodsService.add(addGoodsParam);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody ModifyGoodsParam modifyGoodsParam) {
        goodsService.modify(modifyGoodsParam);
        return R.success();
    }

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

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

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

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<SearchGoodsResult>> paging(PageParam pageParam, SearchGoodsParam goodsParam) {
        return R.success(goodsService.paging(pageParam, goodsParam));
    }
}


