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

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

import jakarta.validation.Valid;

/**
 * 商品问答管理 Controller
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/mall/productQa/v1")
@Tag(name = "商品问答管理")
@AllArgsConstructor
public class MallProductQaController extends BaseController {

    private final MallProductQaApplicationService mallProductQaApplicationService;

    @Operation(summary = "获取详情")
    @GetMapping(value = "info")
    public AjaxResult<MallProductQaInfoVO> info(@RequestParam("id") String id) {
        MallProductQaInfoVO vo = mallProductQaApplicationService.get(id);
        return AjaxResult.okData(vo);
    }

    @Operation(summary = "获取列表（分页）")
    @PostMapping(value = "list")
    public AjaxResult<PageRespVO<MallProductQaListVO>> list(@RequestBody MallProductQaQueryVO query) {
        PageRespVO<MallProductQaListVO> page = mallProductQaApplicationService.findPage(new Page<>(query), query);
        return AjaxResult.okData(page);
    }

    @Operation(summary = "保存")
    @PostMapping(value = "save")
    public AjaxResult<Void> save(@RequestBody @Valid MallProductQaSaveDTO dto) {
        mallProductQaApplicationService.save(dto);
        return AjaxResult.ok("保存成功");
    }

    @Operation(summary = "删除")
    @GetMapping(value = "delete")
    public AjaxResult<Void> delete(@RequestParam("ids") String ids) {
        mallProductQaApplicationService.delete(ids);
        return AjaxResult.ok("删除成功");
    }

    @Operation(summary = "回复问题")
    @PostMapping(value = "reply")
    public AjaxResult<Void> reply(@RequestParam("qaId") String qaId,
                           @RequestParam("answer") String answer,
                           @RequestParam("replyBy") String replyBy) {
        mallProductQaApplicationService.reply(qaId, answer, replyBy);
        return AjaxResult.ok("回复成功");
    }
}
