package com.jwipc.supplier.controller.pc;

import com.jwipc.supplier.constant.ModuleConst;
import com.jwipc.supplier.dto.SupplierTemplateQuestionnaireBaseDTO;
import com.jwipc.supplier.logic.QuestionnaireLogic;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import static com.jwipc.supplier.constant.ModuleConst.MODULE_ROOT;

/**
 * 问卷调查配置相关页面
 */
@RequestMapping(MODULE_ROOT + "/questionnaire/page")
@RequiredArgsConstructor
@Controller
public class QuestionnairePageController {
    private final QuestionnaireLogic questionnaireLogic;

    /**
     * 问卷调查配置页面
     *
     * @param model
     * @param select
     * @return
     */
    @GetMapping("index")
    public String index(Model model, @RequestParam(required = false, defaultValue = "0") Integer select) {
        model.addAttribute("select", select);
        return ModuleConst.MODULE_ROOT + "/questionnaire/index";
    }

    /**
     * 问卷调查新增和编辑页面
     *
     * @param model
     * @param lookupFlag 是否查看 1:是;默认否
     * @param id         问卷调查配置项主键
     * @return
     */
    @GetMapping("detail")
    public String detail(Model model, @RequestParam(required = false, defaultValue = "0") Integer lookupFlag,
                         @RequestParam(required = false, defaultValue = "0") Long id)
    {
        SupplierTemplateQuestionnaireBaseDTO questionnaireBaseDTO = questionnaireLogic.getDetail(id);
        model.addAttribute("questionnaire", questionnaireBaseDTO);
        model.addAttribute("lookupFlag", lookupFlag);
        return ModuleConst.MODULE_ROOT + "/questionnaire/detail";
    }
}
