package com.xinelu.web.controller.familydoctor;

import com.xinelu.common.annotation.MobileRequestAuthorization;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.familydoctor.entity.EvaluateRecord;
import com.xinelu.familydoctor.entity.EvaluateSurvey;
import com.xinelu.familydoctor.service.EvaluateRecordService;
import com.xinelu.familydoctor.service.EvaluateSurveyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author gaoyu
 * @description 自我评估问卷控制器
 * @date 2023-10-10 11:02
 */
@Api(tags = {"自我评估问卷控制器"})
@RestController
@RequestMapping("/evaluate")
public class EvaluateSurveyController extends BaseController {
    @Resource
    private EvaluateSurveyService evaluateSurveyService;
    @Resource
    private EvaluateRecordService evaluateRecordService;

    @ApiOperation("问卷列表")
    @GetMapping("survey/list")
    @MobileRequestAuthorization
    public TableDataInfo surveyList(EvaluateSurvey entity) {
        startPage();
        List<EvaluateSurvey> list = evaluateSurveyService.findList(entity);
        return getDataTable(list);
    }

    @ApiOperation("问卷新增")
    @PostMapping("survey/save")
    public AjaxResult surveySave(@RequestBody EvaluateSurvey entity) {
        evaluateSurveyService.insert(entity);
        return AjaxResult.success();
    }

    @ApiOperation("问卷编辑")
    @PostMapping("survey/update")
    public AjaxResult surveyUpdate(@RequestBody EvaluateSurvey entity) {
        evaluateSurveyService.update(entity);
        return AjaxResult.success();
    }

    @ApiOperation("修改问卷状态（启用/停用）")
    @PostMapping("survey/change/state")
    public AjaxResult changeState() {
        return AjaxResult.success();
    }

    @ApiOperation("获取问卷")
    @GetMapping("survey/get/{subject}")
    @ApiImplicitParam(name = "subject", value = "问卷主题", required = true)
    public AjaxResult getSurvey(@PathVariable String subject) {
        EvaluateSurvey survey = evaluateSurveyService.getSurvey(subject);
        return AjaxResult.success(survey);
    }

    @ApiOperation("问卷提交")
    @PostMapping("survey/submit")
    public AjaxResult surveySubmit(@RequestBody EvaluateRecord evaluateRecord) {
        evaluateRecordService.submit(evaluateRecord);
        return AjaxResult.success();
    }

    @ApiOperation("获取评估记录")
    @GetMapping("record/timeline/{userId}")
    @ApiImplicitParam(name = "userId", value = "用户ID", required = true)
    public AjaxResult record(@PathVariable Long userId) {
        return AjaxResult.success(evaluateRecordService.getEvaluateTimeline(userId));
    }

    @ApiOperation("获取评估问卷答案")
    @GetMapping("survey/answer/{recordId}")
    @ApiImplicitParam(name = "recordId", value = "评估记录ID", required = true)
    public AjaxResult detail(@PathVariable Long recordId) {
        return AjaxResult.success(evaluateRecordService.getAnswers(recordId));
    }
}
