package com.jwipc.supplier.controller.pc;

import com.jwipc.supplier.constant.ModuleConst;
import com.jwipc.supplier.dto.QualificationBaseDTO;
import com.jwipc.supplier.dto.QualificationTemplateBaseDTO;
import com.jwipc.supplier.logic.QualificationLogic;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * <p>注册资质配置</p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@Controller
@RequestMapping(MODULE_ROOT + "/qualification")
@RequiredArgsConstructor
@Slf4j
public class QualificationPageController {
    public final QualificationLogic qualificationLogic;

    /**
     * 注册资质配置列表页面
     * @param model
     * @param scene
     * @return
     */
    @GetMapping("index")
    public String index(Model model,
                        @RequestParam(required = false, defaultValue = "1")String scene,
                        @RequestParam(required = false, defaultValue = "1")String selected,
                        @RequestParam(required = false, defaultValue = "")String codes,
                        @RequestParam(required = false, defaultValue = "1")String single
                        ) {
        model.addAttribute("scene", scene);
        model.addAttribute("selected", selected);
        model.addAttribute("single", single);
        model.addAttribute("codes", codes);
        return ModuleConst.MODULE_ROOT + "/qualification/index";
    }

    /**
     * 注册资质编辑和新增页面
     * @param model
     * @param scene
     * @param id
     * @return
     */
    @GetMapping("detail")
    public String detail(Model model, String scene, @RequestParam(required = false, defaultValue = "0") Long id) {
        model.addAttribute("scene", scene);
        QualificationBaseDTO qualificationBaseDTO = qualificationLogic.getDetail(id);
        model.addAttribute("qualification", qualificationBaseDTO);
        return ModuleConst.MODULE_ROOT + "/qualification/detail";
    }

    /**
     * 资质模板配置主页面
     * @param model
     * @param scene
     * @return
     */
    @GetMapping("template/index")
    public String templateIndex(Model model, String scene) {
        model.addAttribute("scene", scene);
        return ModuleConst.MODULE_ROOT + "/qualification/template_index";
    }

    /**
     * 资质模板配置 编辑和新增页面
     * @param model
     * @param scene
     * @param copyFlag
     * @param id
     * @return
     */
    @GetMapping("template/detail")
    public String templateDetail(Model model, String scene,
                                 @RequestParam(required = false, defaultValue = "0") Integer copyFlag,
                                 @RequestParam(required = false, defaultValue = "0") Long id)
    {
        model.addAttribute("scene", scene);
        model.addAttribute("copyFlag", copyFlag);
        QualificationTemplateBaseDTO qualificationTemplateBaseDTO = qualificationLogic.getTemplateDetail(id);
        model.addAttribute("qualificationTemplate", qualificationTemplateBaseDTO);
        return ModuleConst.MODULE_ROOT + "/qualification/template_detail";
    }
}
