package com.ichangzuo.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ichangzuo.common.result.PageResult;
import com.ichangzuo.common.result.Result;
import com.ichangzuo.system.model.bo.QnABO;
import com.ichangzuo.system.model.bo.QnAFullBO;
import com.ichangzuo.system.model.bo.QnAUpdateBO;
import com.ichangzuo.system.model.query.QnAPageQuery;
import com.ichangzuo.system.service.impl.QnAServiceImpl;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/helper")
@RequiredArgsConstructor
public class HelperController {
    private final QnAServiceImpl qnaService;

    @GetMapping("/listQnA/{id}")
    public Result<List<QnABO>> listQnA(@Parameter(description = "问答ID") @PathVariable Integer id){
        List<QnABO> listBo = qnaService.listByType(id);
        return Result.success(listBo);
    }

    @GetMapping("/pageQnA")
    public PageResult<QnAFullBO> pageQnA(QnAPageQuery queryParams){
        IPage<QnAFullBO> page = qnaService.listPage(queryParams);
        return PageResult.success(page);
    }

    @PutMapping(value = "/updateQnA")
    public Result<?> updateQnA( @RequestBody QnAUpdateBO qnaBo ) {
        boolean result = qnaService.updateOrSave(qnaBo);
        return Result.judge(result);
    }

    @PutMapping(value = "/setQnAByIds/{ids}")
    public Result<?> setByIds(
            @Parameter(description = "QnAID，多个以英文逗号(,)分割") @PathVariable String ids,
            @Parameter(description = "设置状态参数") @RequestParam Integer state
    ) {
        boolean result = qnaService.setByIds(ids,state);
        return Result.judge(result);
    }
}
