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.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("ProblemController")
@RequestMapping("api/front/problem")
@Api(tags = "商品常见问题")
public class ProblemController {

    @Autowired private StoreProductProblemService storeProductProblemService;

    @ApiOperation(value = "常见问题列表")
    @RequestMapping(value = "/{productId}", method = RequestMethod.GET)
    public CommonResult<CommonPage<ProductProblemResponse>> getResponseList(@PathVariable Integer productId, @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(storeProductProblemService.getResponseList(productId, pageParamRequest));
    }

    @ApiOperation(value = "常见问题列表-子回复列表")
    @RequestMapping(value = "/son/{majorId}", method = RequestMethod.GET)
    public CommonResult<CommonPage<ProductProblemResponse>> getSonResponseList(@PathVariable Integer majorId, @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(storeProductProblemService.getSonResponseList(majorId, pageParamRequest));
    }

    @ApiOperation(value = "常见问题-提问/回复")
    @PostMapping("/commit")
    public CommonResult<Void> commitProblem(@RequestBody CommitProblemRequest request) {
        if (storeProductProblemService.commitProblem(request) > 0) {
            return CommonResult.success();
        }
        return CommonResult.failed("提交失败");
    }

    @ApiOperation(value = "常见问题-点赞/取消点赞")
    @RequestMapping(value = "/praise/{majorId}", method = RequestMethod.GET)
    public CommonResult<Void> praise(@PathVariable Integer majorId) {
        if (storeProductProblemService.praiseProblem(majorId) > 0) {
            return CommonResult.success();
        }
        return CommonResult.failed("操作失败");
    }

    @ApiOperation(value = "常见问题列表-删除")
    @RequestMapping(value = "/del/{majorId}", method = RequestMethod.GET)
    public CommonResult<Void> delProblem(@PathVariable Integer majorId) {
        if (storeProductProblemService.delProblem(majorId) > 0) {
            return CommonResult.success();
        }
        return CommonResult.failed("删除失败");
    }

}



