package com.ym.mec.student.controller;

import com.ym.mec.biz.dal.dto.LiveGoodsMapperDto;
import com.ym.mec.biz.dal.entity.LiveGoods;
import com.ym.mec.biz.dal.page.LiveGoodsMapperQueryInfo;
import com.ym.mec.biz.service.LiveGoodsMapperService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "直播商品关联管理")
@RequestMapping("liveGoodsMapper")
@RestController
public class LiveGoodsMapperController extends BaseController {

    @Autowired
    private LiveGoodsMapperService liveGoodsMapperService;

    @ApiOperation("分页查询直播间商品")
    @PostMapping("/page")
    public HttpResponseResult<PageInfo<LiveGoodsMapperDto>> page(LiveGoodsMapperQueryInfo queryInfo) {
        return succeed(liveGoodsMapperService.queryGoodsPage(queryInfo));
    }

    @ApiOperation("获取直播间商品详情")
    @GetMapping(value = "/getGoodsDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "liveGoodsId", value = "商品编号", required = true, dataType = "long"),
            @ApiImplicitParam(name = "liveId", value = "房间号", required = true,dataType = "String")
    })
    public HttpResponseResult<LiveGoodsMapperDto> getGoodsDetail(Integer liveGoodsId, String liveId) {
        List<LiveGoodsMapperDto> liveGoodsList = liveGoodsMapperService.getLiveGoodsList(liveId, liveGoodsId, null);
        if (liveGoodsList.size() > 0) {
            return succeed(liveGoodsList.get(0));
        }
        return failed("商品不存在");
    }
}
