package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.entity.LiveGoods;
import com.ym.mec.biz.dal.page.LiveGoodsQueryInfo;
import com.ym.mec.biz.service.LiveGoodsService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(tags = "直播间商品管理")
@RequestMapping("liveGoods")
@RestController
public class LiveGoodsController extends BaseController {

    @Autowired
    private LiveGoodsService liveGoodsService;

    @ApiOperation("获取商品详情")
    @GetMapping(value = "/get")
    @PreAuthorize("@pcs.hasPermissions('liveGoods/get')")
    public HttpResponseResult get(Integer goodsId) {
        return succeed(liveGoodsService.get(goodsId));
    }

    @ApiOperation("分页查询直播间商品")
    @PostMapping(value = "/page")
    @PreAuthorize("@pcs.hasPermissions('liveGoods/page')")
    public HttpResponseResult page(LiveGoodsQueryInfo queryInfo) {
        return succeed(liveGoodsService.queryGoodsPage(queryInfo));
    }

    @ApiOperation("新增直播间商品")
    @PostMapping("/add")
    @PreAuthorize("@pcs.hasPermissions('liveGoods/add')")
    public HttpResponseResult add(@RequestBody LiveGoods liveGoods) {
        liveGoodsService.add(liveGoods);
        return succeed();
    }

    @ApiOperation("修改直播间商品")
    @PostMapping(value = "/update")
    @PreAuthorize("@pcs.hasPermissions('liveGoods/update')")
    public HttpResponseResult update(@RequestBody LiveGoods liveGoods) {
        liveGoodsService.updateLiveGoods(liveGoods);
        return succeed();
    }

    @ApiOperation("删除直播间商品")
    @PostMapping(value = "/delete")
    @PreAuthorize("@pcs.hasPermissions('liveGoods/delete')")
    public HttpResponseResult delete(Integer goodsId) {
        liveGoodsService.deleteLiveGoods(goodsId);
        return succeed();
    }

//    @ApiOperation("上架、下架直播间商品")
//    @PostMapping("/updateStatus")
//    @PreAuthorize("@pcs.hasPermissions('liveGoods/updateStatus')")
//    public HttpResponseResult updateStatus(Integer liveGoodsId, Boolean status) {
//        liveGoodsService.updateStatus(liveGoodsId, status);
//        return succeed();
//    }
}
