package com.yc.ship.module.miniapplet.controller.app.problem;

import com.yc.ship.framework.common.pojo.CommonResult;
import com.yc.ship.framework.common.util.object.BeanUtils;
import com.yc.ship.module.miniapplet.controller.app.problem.vo.AppProblemReqVO;
import com.yc.ship.module.miniapplet.controller.app.problem.vo.AppProblemRespVO;
import com.yc.ship.module.miniapplet.controller.app.problem.vo.AppProblemTypeRespVO;
import com.yc.ship.module.miniapplet.dal.dataobject.problem.ProblemDO;
import com.yc.ship.module.miniapplet.dal.dataobject.problemtype.ProblemTypeDO;
import com.yc.ship.module.miniapplet.service.problem.ProblemService;
import com.yc.ship.module.miniapplet.service.problemtype.ProblemTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static com.yc.ship.framework.common.pojo.CommonResult.success;

/**
 *
 * @description ：TODO
 * @date ：2024/8/19 17:13
 */
@Tag(name = "用户 APP - 问题类型/问题")
@RestController
@RequestMapping("/app/applet/problem")
@Validated
@Slf4j
public class AppProblemController {

    @Resource
    private ProblemTypeService problemTypeService;

    @Resource
    private ProblemService problemService;

    @PostMapping("/problemTypeList")
    @Operation(summary = "获取问题类型列表")
    public CommonResult<List<AppProblemTypeRespVO>> problemTypeList(@RequestBody @Valid AppProblemReqVO reqVO) {
        List<ProblemTypeDO> problemTypeList = problemTypeService.getProblemTypeListByApp(reqVO);
        List<AppProblemTypeRespVO> respVOS = BeanUtils.toBean(problemTypeList, AppProblemTypeRespVO.class);
        return success(respVOS);
    }

    @PostMapping("/problemType")
    @Operation(summary = "获取问题类型详情")
    public CommonResult<AppProblemTypeRespVO> problemType(@RequestBody @Valid AppProblemReqVO reqVO) {
        ProblemTypeDO problemTypeDO = problemTypeService.getProblemType(reqVO.getProblemTypeId());
        AppProblemTypeRespVO respVO = BeanUtils.toBean(problemTypeDO, AppProblemTypeRespVO.class);
        return success(respVO);
    }

    @PostMapping("/problemList")
    @Operation(summary = "获取问题列表")
    public CommonResult<List<AppProblemRespVO>> problemList(@RequestBody @Valid AppProblemReqVO reqVO) {
        List<ProblemDO> problemList = problemService.getProblemList(reqVO);
        List<AppProblemRespVO> respVOS = BeanUtils.toBean(problemList, AppProblemRespVO.class);
        return success(respVOS);
    }

    @PostMapping("/problem")
    @Operation(summary = "获取问题详情")
    public CommonResult<AppProblemRespVO> problem(@RequestBody @Valid AppProblemReqVO reqVO) {
        ProblemDO problemDO = problemService.getProblem(reqVO.getProblemId());
        AppProblemRespVO respVO = BeanUtils.toBean(problemDO, AppProblemRespVO.class);
        return success(respVO);
    }

}
