package com.zbkj.front.controller;


import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.*;
import com.zbkj.common.response.*;
import com.zbkj.common.vo.CategoryTreeVo;
import com.zbkj.front.service.ProductService;
import com.zbkj.service.service.StoreProductProblemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户 -- 用户中心

 */
@Slf4j
@RestController("ProductController")
@RequestMapping("api/front")
@Api(tags = "商品")
public class ProductController {

    @Autowired private ProductService productService;

    /**
     * 1.购物车/我的为你推荐（是否热卖）
     * 2.首页精品商品推荐（是否精品）
     */
    @ApiOperation(value = "首页商品列表")
    @RequestMapping(value = "/product/{type}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "type", value = "类型【1首页精品推荐, 2为你推荐】", dataType = "int", required = true)
    public CommonResult<CommonPage<IndexProductResponse>> getProductList(@PathVariable(value = "type") Integer type, PageParamRequest pageParamRequest) {
        return CommonResult.success(productService.getProductListByType(type, pageParamRequest));
    }

    /**
     * 获取一级分类
     */
    @ApiOperation(value = "获取分类-一级")
    @RequestMapping(value = "/category/top", method = RequestMethod.GET)
    public CommonResult<List<CategoryTreeVo>> getCategoryTop() {
        return CommonResult.success(productService.getCategoryTop());
    }

    /**
     * 获取分类
     */
    @ApiOperation(value = "获取分类-树形")
    @RequestMapping(value = "/category", method = RequestMethod.GET)
    public CommonResult<List<CategoryTreeVo>> getCategory() {
        return CommonResult.success(productService.getCategory());
    }

    /**
     * 商品列表
     */
    @ApiOperation(value = "商品列表")
    @RequestMapping(value = "/products", method = RequestMethod.GET)
    public CommonResult<CommonPage<IndexProductResponse>> getList(@Validated ProductRequest request, @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(productService.getList(request, pageParamRequest));
    }

    /**
     * 商品详情
     */
    @ApiOperation(value = "商品详情")
    @RequestMapping(value = "/product/detail/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "type", value = "normal-正常")
    public CommonResult<ProductDetailResponse> getDetail(@PathVariable Integer id, @RequestParam(value = "type", defaultValue = "normal") String type) {
        return CommonResult.success(productService.getDetail(id, type));
    }

    /**
     * 商品规格详情
     */
    @ApiOperation(value = "商品规格详情")
    @RequestMapping(value = "/product/sku/detail/{id}", method = RequestMethod.GET)
    public CommonResult<ProductDetailResponse> getSkuDetail(@PathVariable Integer id) {
        return CommonResult.success(productService.getSkuDetail(id));
    }

//    /**
//     * 商品列表
//     */
//    @ApiOperation(value = "商品列表(个别分类模型使用)")
//    @RequestMapping(value = "/product/list", method = RequestMethod.GET)
//    public CommonResult<CommonPage<IndexProductResponse>> getProductList(@Validated ProductListRequest request, @Validated PageParamRequest pageParamRequest) {
//        return CommonResult.success(productService.getCategoryProductList(request, pageParamRequest));
//    }

    /**
     * 商品详情评论
     */
    @ApiOperation(value = "商品详情评论")
    @RequestMapping(value = "/reply/product/{id}", method = RequestMethod.GET)
    public CommonResult<ProductDetailReplyResponse> getProductReply(@PathVariable Integer id) {
        return CommonResult.success(productService.getProductReply(id));
    }

    /**
     * 商品评论数量
     */
    @ApiOperation(value = "商品评论数量")
    @RequestMapping(value = "/reply/config/{id}", method = RequestMethod.GET)
    public CommonResult<StoreProductReplayCountResponse> getReplyCount(@PathVariable Integer id) {
        return CommonResult.success(productService.getReplyCount(id));
    }

    /**
     * 商品评论列表
     */
    @ApiOperation(value = "商品评论列表")
    @RequestMapping(value = "/reply/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<ProductReplyResponse>> getReplyList(@Validated GetReplyListRequest request, @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(productService.getReplyList(request, pageParamRequest)));
    }

//    /**
//     * 商品排行榜
//     */
//    @ApiOperation(value = "商品排行榜")
//    @RequestMapping(value = "/product/leaderboard", method = RequestMethod.GET)
//    public CommonResult<List<StoreProduct>> getLeaderboard() {
//        return CommonResult.success(productService.getLeaderboard());
//    }
}



