package com.jeesharp.business.modules.mall.controller;

import com.jeesharp.business.modules.mall.application.MallProductQaApplicationService;
import com.jeesharp.business.modules.mall.vo.MallProductQaListVO;
import com.jeesharp.framework.pojo.AjaxResult;
import com.jeesharp.framework.pojo.Page;
import com.jeesharp.framework.pojo.query.PageRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 商品问答移动端 Controller
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/mall/productQa/v1")
@Tag(name = "商品问答")
@AllArgsConstructor
public class MallProductQaMobileController {

    private final MallProductQaApplicationService mallProductQaApplicationService;

    @Operation(summary = "用户提问")
    @PostMapping(value = "add")
    public AjaxResult<Void> add(@RequestParam("memberId") String memberId,
                         @RequestParam("spuId") String spuId,
                         @RequestParam("question") String question,
                         @RequestParam(value = "isAnonymous", defaultValue = "0") Integer isAnonymous) {
        mallProductQaApplicationService.addQuestion(memberId, spuId, question, isAnonymous);
        return AjaxResult.ok("提问成功");
    }

    @Operation(summary = "商品问答列表")
    @PostMapping(value = "list")
    public AjaxResult<PageRespVO<MallProductQaListVO>> list(@RequestParam("spuId") String spuId,
                          @RequestParam(value = "pageNo", defaultValue = "1") Long pageNo,
                          @RequestParam(value = "pageSize", defaultValue = "10") Long pageSize) {
        PageRespVO<MallProductQaListVO> page = mallProductQaApplicationService.getProductQaList(spuId,
            new Page<>(pageNo, pageSize));
        return AjaxResult.okData(page);
    }
}
