package com.zhongshu.card.server.core.controller.quest;

import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.quest.*;
import com.zhongshu.card.server.core.domain.quest.QuestionClean;
import com.zhongshu.card.server.core.service.quest.DataClean;
import com.zhongshu.card.server.core.service.quest.QuestService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author TRX
 * @date 2024/6/5
 */
@RestController
@RequestMapping("/questInfo")
@Tag(name = "问卷调查")
public class QuestInfoController {

    @Autowired
    private QuestService questService;

    @Autowired
    private DataClean dataClean;

    @Operation(summary = "添加问卷结果", description = "添加问卷结果")
    @RequestMapping(value = "saveInfo", method = {RequestMethod.POST})
    public ResultContent saveInfo(@RequestBody QuestInfoParam param) {
        return this.questService.saveInfo(param);
    }

    @Operation(summary = "编辑问卷结果", description = "添加问卷结果")
    @RequestMapping(value = "updateInfo", method = {RequestMethod.POST})
    public ResultContent updateInfo(@RequestBody QuestInfoUpdateParam param) {
        return this.questService.updateInfo(param);
    }

    @Operation(summary = "删除", description = "删除")
    @RequestMapping(value = "deleteById", method = {RequestMethod.POST})
    public ResultContent deleteById(@RequestBody PsdParam param) {
        return this.questService.deleteById(param);
    }

    @Operation(summary = "列表-分页查询", description = "列表-分页查询")
    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<QuestInfoModel>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) QuestInfoSearch param) {
        return questService.page(param, pageable);
    }

    @RequestMapping(value = "exportData", method = RequestMethod.POST)
    @Operation(summary = "导出数据", description = "导出数据")
    public void exportData(HttpServletRequest request, HttpServletResponse response, QuestInfoSearch param) throws Exception {
        questService.exportData(request, response, param);
    }

    @RequestMapping(value = "dataClean", method = RequestMethod.POST)
    @Operation(summary = "数据清洗", description = "数据清洗")
    public Object dataClean() {
        return dataClean.clean();
    }

    @RequestMapping(value = "exportCleanData", method = RequestMethod.POST)
    @Operation(summary = "导出清洗数据", description = "导出清洗数据")
    public void exportCleanData(HttpServletRequest request, HttpServletResponse response) throws Exception {
        dataClean.exportCleanData(request, response);
    }
}
