package com.ruoyi.web.controller.mall;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.RestResponse;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.mall.domain.UserFavorite;
import com.ruoyi.mall.service.UserFavoriteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "app商品收藏")
@RestController
@RequestMapping("/api/userFavorite")
public class UserFavoriteController {

    @Autowired
    private UserFavoriteService service;

    /**
     * 商品收藏
     * @return
     */
    @ApiOperation("收藏")
    @PostMapping("/add")
    public RestResponse addFavorite(@RequestBody UserFavorite favorite){
        return new RestResponse().setSuccess(true).setData(service.addFavorite(favorite.getProductId()));
    }


    /**
     * 判断商品是否收藏
     * @return
     */
    @ApiOperation("判断商品是否收藏")
    @PostMapping("/existsByProductId")
    public RestResponse existsByProductId(@RequestBody UserFavorite favorite){
            Long userId=SecurityUtils.getAppLoginUser().getAppUserId();;
        return new RestResponse().setSuccess(true).setData(service.existsByUserIdAndProductId(userId,favorite.getProductId()));
    }

    /**
     * 取消收藏
     */
    @ApiOperation("取消收藏")
    @PostMapping("/removeFavorite")
    public RestResponse removeFavorite(@RequestBody UserFavorite favorite) {
        Long userId=SecurityUtils.getAppLoginUser().getAppUserId();;
        return new RestResponse().setSuccess(true).setData(service.removeFavorite(userId,favorite.getProductId()));
    }

    /**
     * 获取用户的收藏列表
     */
    @ApiOperation("获取用户的收藏列表")
    @GetMapping("/getUserFavorites")
    public RestResponse getUserFavorites() {
        return new RestResponse().setSuccess(true).setData(service.getUserFavorites());
    }


    /**
     * 获取用户的收藏数量
     */
    @ApiOperation("获取用户的收藏数量")
    @GetMapping("/getUserFavoriteCount")
    public RestResponse getUserFavoriteCount() {
        return new RestResponse().setSuccess(true).setData(service.getUserFavoriteCount());
    }
}
