package com.gree.mall.miniapp.controller.goods;

import com.gree.mall.miniapp.bean.Page;
import com.gree.mall.miniapp.bean.goods.CategoryBean;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.goods.GoodsFavoriteLogic;
import com.gree.mall.miniapp.plus.entity.GoodsFavorite;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@Api(value = "商品收藏", tags ={"商品收藏"} )
@RequestMapping(value = "/goods/favorite", produces = "application/json; charset=utf-8")
public class GoodsFavoriteController {

    @Autowired
    private GoodsFavoriteLogic goodsFavoriteLogic;

    @PostMapping("/add")
    @ApiOperation(value = "添加收藏")
    public ResponseHelper<GoodsFavorite> add(
            HttpServletRequest request,
            @ApiParam(required = true, value = "用户id") @RequestParam(required = true) String userId,
            @ApiParam(required = true, value = "商品id") @RequestParam(required = true) String goodsId,
            @ApiParam(required = false, value = "商品规格id") @RequestParam(required = false) String goodsSpecId
    ) throws Exception {
        GoodsFavorite goodsFavorite = goodsFavoriteLogic.saveGoodsFavorite(request , userId, goodsId, goodsSpecId);
        return ResponseHelper.success(goodsFavorite);
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除收藏")
    public ResponseHelper<GoodsFavorite> del(
            @ApiParam(required = true, value = "商品收藏id") @RequestParam(required = true) String goodFavoriteId

    ) throws Exception {
        goodsFavoriteLogic.delGoodsFavorite(goodFavoriteId);
        return ResponseHelper.success();
    }

    @PostMapping("/detail/del")
    @ApiOperation(value = "从商品详情页面删除收藏")
    public ResponseHelper<GoodsFavorite> detailDel(
            @ApiParam(required = true, value = "商品id") @RequestParam(required = true) String goodsId,
            @ApiParam(required = true, value = "用户id") @RequestParam(required = true) String userId,
            @ApiParam(required = false, value = "商品规格id") @RequestParam(required = false) String goodSpecId

    ) throws Exception {
        goodsFavoriteLogic.detailDelGoodsFavorite(goodsId,userId,goodSpecId);
        return ResponseHelper.success();
    }

    @GetMapping("/query")
    @ApiOperation(value = "获取商品收藏列表")
    public ResponseHelper<GoodsFavorite> queryList(
            @ApiParam(required = true, value = "用户id") @RequestParam(required = true) String userId,
            @ApiParam(value = "页号",required = true) @RequestParam Integer pageNum,
            @ApiParam(value = "页大小",required = true) @RequestParam Integer pageSize
    ) throws Exception {
        Page page = goodsFavoriteLogic.pageGoodsFavorite(userId, pageNum, pageSize);
        return ResponseHelper.success(page);
    }




}
