package org.lym.pom.controller.moment;

import jakarta.servlet.http.HttpServletRequest;
import org.lym.pom.controller.moment.ui.response.user.UserInfoResponse;
import org.shoulder.core.dto.response.BaseResult;
import org.shoulder.core.exception.BaseRuntimeException;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author lym
 **/
@Controller
@RequestMapping("/")
public class VueController {

    @GetMapping(value = {"/article/editor", "/faq/editor", "/faq/editor/{id}", "/article/editor/{id}"})
    public String editor() {
        return "vue-index";
    }

    @GetMapping(value = {"/admin"
            , "/admin/user-manager", "/admin/user-opt-log"
            , "/admin/article-manager", "/admin/article-type"
            , "/admin/faq-manager"
            , "/admin/message-manager"
            , "/admin/tag-manager"})
    public String admin(HttpServletRequest request) {
        String sid = parseSessionInfo(request);
        if (ObjectUtils.isEmpty(sid)) {
            throw new BaseRuntimeException("用户未登录");
        }

        BaseResult<UserInfoResponse> BaseResult = parseUserInfo(sid);
        if (!BaseResult.isSuccess() || ObjectUtils.isEmpty(BaseResult.getData())) {
            throw new BaseRuntimeException(BaseResult.getMsg());
        }
        UserInfoResponse userInfoResponse = BaseResult.getData();
        if ("USER".equals(userInfoResponse.getRole())) {
            throw new BaseRuntimeException("无权限访问");
        }

        return "vue-admin";
    }

    private String parseSessionInfo(HttpServletRequest request) {
        return "todoSessionId";
    }

    private BaseResult<UserInfoResponse> parseUserInfo(String sid) {
        return BaseResult.success();
    }

}
