package com.sckw.goods.controller;

import com.sckw.goods.entity.req.GoodsFindListParam;
import com.sckw.goods.entity.req.GoodsInsertParam;
import com.sckw.goods.entity.req.GoodsPageParam;
import com.sckw.goods.entity.req.GoodsUpdateParam;
import com.sckw.goods.entity.res.GoodsDetailByIdRes;
import com.sckw.goods.entity.res.GoodsFindListRes;
import com.sckw.goods.service.GoodsService;
import com.sckw.core.model.page.PageRes;
import com.sckw.core.web.response.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @desc: 商品
 * @author: Lt
 * @date: 2024-04-26
 */
@Validated
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;


    /**
     * 分页查询
     *
     * @param params
     * @return
     */
    @PostMapping("/findPage")
    public HttpResult findPage(@RequestBody GoodsPageParam params) {
        return HttpResult.ok(goodsService.findPage(params));
    }

    /**
     * 列表查询
     * @param params
     * @return
     */
    @PostMapping("/findList")
    public HttpResult findList(@RequestBody(required = false) GoodsFindListParam params) {
        PageRes<GoodsFindListRes> list = goodsService.findList(params);
        return HttpResult.ok(list);
    }

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public HttpResult findById(@PathVariable("id") Long id) {
        GoodsDetailByIdRes kwBusinessGoods = goodsService.findById(id);
        return HttpResult.ok(kwBusinessGoods);
    }

    /**
     * 新增
     */
    @PostMapping("/insert")
    public HttpResult insert(@Validated  @RequestBody GoodsInsertParam goodsInsertParam) {
        int result = goodsService.insert(goodsInsertParam);
        return HttpResult.ok(result);
    }

    /**
     * 修改
     *
     * @return
     */
    @PostMapping("/update")
    public HttpResult update( @Validated  @RequestBody GoodsUpdateParam goodsUpdateParam) {
        int result = goodsService.update(goodsUpdateParam);
        return HttpResult.ok(result);
    }

    /**
     * 删除
     *
     * @return
     */
    @PostMapping("/delete")
    public HttpResult delete(@RequestParam(value = "ids") List<Long> ids) {
        int result = goodsService.delete(ids);
        return HttpResult.ok(result);
    }



}
