package com.sptg.permissions.biz.controller;

import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.OperationConstant;
import com.sptg.common.core.util.TreeUtil;
import com.sptg.permissions.api.dto.AccountDto;
import com.sptg.permissions.api.dto.LoginDto;
import com.sptg.permissions.api.entity.Account;
import com.sptg.permissions.api.entity.Menu;
import com.sptg.permissions.api.entity.Role;
import com.sptg.permissions.api.enums.PermissionsEnum;
import com.sptg.permissions.api.feigns.ThirdAuthenticationFeign;
import com.sptg.permissions.api.thirdauth.util.AuthRequestUtil;
import com.sptg.permissions.biz.service.AccountRoleServiceInterface;
import com.sptg.permissions.biz.service.AccountServiceInterface;
import com.sptg.permissions.biz.service.MenuServiceInterface;
import com.sptg.permissions.biz.service.RoleServiceInterface;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.utils.AuthStateUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * title: ThirdAuthenticationController
 * package: com.sptg.permissions.biz.controller
 * description: 第三方授权认证-控制器
 *
 *                  
 *                 
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class ThirdAuthenticationController implements ThirdAuthenticationFeign {


    @Override
    @RequestMapping("/render/{source}")
    @ResponseBody
    public void renderAuth(String source, HttpServletResponse response) throws IOException {
        log.info("进入render：" + source);
        AuthRequest authRequest = AuthRequestUtil.getAuthRequest(source);
        String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
        log.info(authorizeUrl);
        response.sendRedirect(authorizeUrl);
    }

    @Override
    @RequestMapping("/callback/{source}")
    public ModelAndView login(String source, AuthCallback callback, HttpServletRequest request) {
        return null;
    }

}
