package com.sqx.modules.goods.controller.app;

import cn.hutool.core.util.StrUtil;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.goods.dto.ShopQueryDTO;
import com.sqx.modules.goods.entity.GoodsShop;
import com.sqx.modules.goods.service.GoodsService;
import com.sqx.modules.goods.service.GoodsShopService;
import com.sqx.modules.shop.service.SearchHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags={"用户端-商品"})
@RestController
@RequestMapping("/app/goods")
public class AppGoodsController {

    @Autowired
    private GoodsService goodsService;
    @Autowired
    private SearchHistoryService searchHistoryService;
    @Autowired
    private GoodsShopService goodsShopService;

    @ApiOperation("查看附近的店铺")
    @PostMapping(value = "selectShortShop")
    public Result selectShortShop(double lng, double lat, String shopName, Integer page, Integer limit, Long shopId){

        return goodsService.selectShortShop(lng, lat, shopName, page, limit, shopId);
    }

    @ApiOperation("根据商铺id查看商品列表")
    @GetMapping(value = "/selectGoodsList")
    public Result selectGoodsList(Long shopId, Double lng, Double lat){

        return goodsService.selectGoodsList(shopId, lng, lat);
    }

    @ApiOperation("查看商品详情")
    @GetMapping(value = "/selectGoodsById")
    public Result selectGoodsById(Long goodsId){

        return goodsService.selectGoodsById(goodsId);
    }

    /*@Login
    @ApiOperation("获取该商品规格名")
    @GetMapping(value = "selectSkuByGoodsId")
    public Result selectSkuByGoodsId(Long goodsId){
        //goodsService.selectSkuByGoodsId(goodsId)
        return null;
    }

    @Login
    @ApiOperation("获取该商品详细规格")
    @GetMapping(value = "selectAttrByGoodsId")
    public Result selectAttrByGoodsId(Long goodsId){
        //goodsService.selectAttrByGoodsId(goodsId);
        return null;
    }*/

    @ApiOperation("条件筛选店铺")
    @GetMapping(value = "selectShop")
    public Result selectShop(ShopQueryDTO queryDTO){
        if (StrUtil.isNotBlank(queryDTO.getImpotr())) {
            //添加历史搜索记录
            searchHistoryService.insertSearchHistory(queryDTO.getUserId(), queryDTO.getImpotr());
        }
        //screen ==1 综合排序(评分)， == 2 商户类型筛选， == 3 距离排序，  ==4 销量,  ==5 配送费排序， ==6 免配送费筛选
        //排序：评分，销量，距离，配送费最低，起送价最低。。。。。
        //筛选：免配送费，
        return goodsService.selectShop(queryDTO);
    }

    @ApiOperation("查看商铺评价")
    @GetMapping(value = "selectEvaluateByShopId")
    public Result selectEvaluateByShopId(Integer page, Integer limit, Long shopId,String goodsId, Integer grade){

        return goodsService.selectEvaluate(page, limit, shopId,goodsId, grade);
    }

    // TODO 待活动重构完成后看是否需要补充该接口
    // @GetMapping("/getShopActivity")
    // @ApiOperation("获取商家所在活动")
    // public Result getShopActivity(Long shopId){
    //     return Result.success().put("data", goodsShopService.getShopActivity(shopId));
    // }

    @ApiOperation("筛选供应商")
    @GetMapping(value = "selectSupplierShop")
    public Result selectSupplierShop(ShopQueryDTO queryDTO){
        if (StrUtil.isNotBlank(queryDTO.getImpotr())) {
            //添加历史搜索记录
            searchHistoryService.insertSearchHistory(queryDTO.getUserId(), queryDTO.getImpotr());
        }
        //screen ==1 综合排序(评分)， == 2 商户类型筛选， == 3 距离排序，  ==4 销量,  ==5 配送费排序， ==6 免配送费筛选
        //排序：评分，销量，距离，配送费最低，起送价最低。。。。。
        //筛选：免配送费，
        return goodsService.selectSupplierShop(queryDTO);
    }

    @ApiOperation("根据商铺id查看消息订阅")
    @GetMapping(value = "/selectGoodShop")
    public Result selectGoodShop(Long shopId){

        return goodsService.selectGoodShop(shopId);
    }

    @ApiOperation("修改消息订阅")
    @PostMapping(value = "/updateGoodShop")
    public Result updateGoodShop(@RequestBody GoodsShop goodsShop){

        return goodsService.updateGoodShop(goodsShop);
    }

    @ApiOperation("查询商品封面图")
    @GetMapping(value = "/goodsCoverList")
    public Result goodsCoverList(Integer page,Integer limit, String name) {
        return goodsService.goodsCoverList(page,limit,name);
    }

    @ApiOperation("查询商品图")
    @GetMapping(value = "/goodsPictureList")
    public Result goodsPictureList(Integer page, Integer limit, String name) {
        return goodsService.goodsPictureList(page,limit,name);
    }

    @ApiOperation("查询商品详情图")
    @GetMapping(value = "/goodsParticularsPictureList")
    public Result goodsParticularsPictureList(Integer page, Integer limit, String name) {
        return goodsService.goodsParticularsPictureList(page,limit,name);
    }

}
