package com.caimei.www.controller.unlimited;

import com.caimei.www.controller.BaseController;
import com.caimei.www.pojo.JsonModel;
import com.caimei.www.pojo.page.PageContent;
import com.caimei.www.pojo.save.Suggestion;
import com.caimei.www.service.page.HelpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Description
 *
 * @author : Charles
 * @date : 2020/7/31
 */
@Controller
public class HelpPageController extends BaseController {

	private static final String HELP_PAGE_PATH = "help/help";

    private HelpService helpService;
    @Autowired
    public void setHelpService(HelpService helpService) {
        this.helpService = helpService;
    }

    /**
     * 帮助页
     */
    @GetMapping("/help/{id}.html")
    public String help(final Model model, @PathVariable Integer id ) {
        PageContent helpPage = helpService.getHelpPageById(id);
        if(null == helpPage){
            // 默认平台介绍
            return "redirect:/help/1016.html";
        }
        model.addAttribute("pageId", id);
        model.addAttribute("pageTypeId", helpPage.getType());
        model.addAttribute("pageInfo", helpPage);
        return HELP_PAGE_PATH;
    }

    /**
     * 保存投诉建议
     * @param suggestion
     * @return
     */
    @PostMapping("/help/suggestion")
    @ResponseBody
    public JsonModel suggestion(Suggestion suggestion) {
        return helpService.suggestionSave(suggestion);
    }
}
