package ink.wgink.login.base.controller.route.login;

import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.login.base.consts.IUserCenterConst;
import ink.wgink.login.base.service.IOAuthService;
import ink.wgink.login.base.service.login.ILoginFormService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: LoginFormRouteController
 * @Description: 登录form
 * @Author: wanggeng
 * @Date: 2021/7/29 4:25 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "登录form")
@Controller
@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/login-form")
public class LoginFormRouteController {

    @Autowired
    private IOAuthService oauthService;
    @Autowired
    private ILoginFormService loginFormService;

    @GetMapping("save")
    public ModelAndView save() {
        return new ModelAndView("login/form/save");
    }

    @GetMapping("update")
    public ModelAndView update() {
        return new ModelAndView("login/form/update");
    }

    @GetMapping("list")
    public ModelAndView list() {
        return new ModelAndView("login/form/list");
    }

    @GetMapping("get-login-preview/{loginFormId}")
    public ModelAndView getLoginPreview(@PathVariable("loginFormId") String loginFormId, HttpServletRequest request) {
        ModelAndView mv = new ModelAndView("login/form/get-login-preview");
        mv.addObject(IUserCenterConst.PAGE_PARAMS, oauthService.getPageParams(request));
        mv.addObject(IUserCenterConst.CUSTOM_LOGIN_FORM, loginFormService.get(loginFormId));
        mv.setViewName("login/form/get-login-preview");
        return mv;
    }

}
