package shop.alien.second.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiSort;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.second.vo.SecondGoodsRecommendVo;
import shop.alien.second.service.SecondRecommendService;

@Slf4j
@Api(tags = {"二手平台-商品列表"})
@ApiSort(9)
@CrossOrigin
@RestController
@RequestMapping("/recommend")
@RequiredArgsConstructor
public class SecondRecommendController {

    private final SecondRecommendService service;

    @ApiOperation("搜索推荐商品列表")
    @PostMapping("/queryRecommendList")
    public R<IPage<SecondGoodsRecommendVo>> queryRecommendList(
            @RequestParam(value = "pageNum", required = false) Integer pageNum,
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
            @RequestParam(value = "typeId", required = false) Integer typeId,
            @RequestParam(value = "longitude", required = false) String longitude,
            @RequestParam(value = "latitude", required = false) String latitude,
            @RequestParam(value = "radiusKm", required = false) String radiusKm) throws Exception {
        log.info("LifeCollectController.cancelCollect?pageNum={},pageSize={},longitude={},latitude={},typeId={}", pageNum, pageSize, longitude, latitude, typeId);
        IPage<SecondGoodsRecommendVo> page = new Page<>(pageNum, pageSize);
        IPage<SecondGoodsRecommendVo> result = service.getSecondRecommendByPage(page, longitude, latitude, typeId, radiusKm);
        return R.data(result, "查询成功");
    }

    @ApiOperation("搜索关注商品列表")
    @PostMapping("/querySecondConcernByPage")
    public R<IPage<SecondGoodsRecommendVo>> querySecondConcernByPage(
            @RequestParam(value = "pageNum", required = false) Integer pageNum,
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
            @RequestParam(value = "longitude", required = false) String longitude,
            @RequestParam(value = "latitude", required = false) String latitude) throws Exception {
        log.info("LifeCollectController.cancelCollect?pageNum={},pageSize={},longitude={},latitude={}", pageNum, pageSize, longitude, latitude);
        IPage<SecondGoodsRecommendVo> page = new Page<>(pageNum, pageSize);
        IPage<SecondGoodsRecommendVo> result = service.querySecondConcernByPage(page, longitude + "," + latitude);
        return R.data(result, "查询成功");
    }

    @ApiOperation("搜索新品商品列表")
    @PostMapping("/querySecondNewGoodsByPage")
    public R<IPage<SecondGoodsRecommendVo>> querySecondNewGoodsByPage(
            @RequestParam(value = "pageNum", required = false) Integer pageNum,
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
            @RequestParam(value = "longitude", required = false) String longitude,
            @RequestParam(value = "latitude", required = false) String latitude,
            @RequestParam(value = "radiusKm", required = false) String radiusKm) throws Exception {
        log.info("LifeCollectController.cancelCollect?pageNum={},pageSize={},longitude={},latitude={}", pageNum, pageSize, longitude, latitude);
        IPage<SecondGoodsRecommendVo> page = new Page<>(pageNum, pageSize);
        IPage<SecondGoodsRecommendVo> result = service.querySecondNewGoodsByPage(page, longitude + "," + latitude, radiusKm);
        return R.data(result, "查询成功");
    }

    @ApiOperation("搜索商品详情")
    @PostMapping("/querySecondGoodsDetail")
    public R<SecondGoodsRecommendVo> querySecondGoodsDetail(
            @RequestParam(value = "goodsId", required = false) Integer goodsId,
            @RequestParam(value = "longitude", required = false) String longitude,
            @RequestParam(value = "latitude", required = false) String latitude) throws Exception {
        log.info("LifeCollectController.cancelCollect?goodsId={},longitude={},latitude={}", goodsId, longitude, latitude);
        return R.data(service.querySecondGoodsDetail(goodsId, longitude + "," + latitude), "查询成功");
    }

}
