package org.jeecg.modules.ctop.controller;

import cn.com.ctop.common.module.service.IBindAccountAuthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;

/**
 * TODO 可以删除
 */
@Controller
@RequestMapping("/auth")
public class AuthController {
    private static final Logger logger = LoggerFactory.getLogger(AuthController.class);

    @Autowired
    private IBindAccountAuthService bindAccountAuthService;


    @RequestMapping("/begin")
    public String authBegin(HttpServletRequest request,
                            HttpServletResponse response,
                            @RequestParam("auth_type") String authType) {
        try {
            String codeUrl = "";
            switch (authType) {
                case "bytedance":
                    codeUrl = bindAccountAuthService.getByteDanceCodeUrl(UUID.randomUUID().toString());
                    return "redirect:" + codeUrl;
                case "kuaishou":
                    codeUrl = bindAccountAuthService.getKuaishouCodeUrl(UUID.randomUUID().toString());
                    return "redirect:" + codeUrl;
                default:
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "auth_error";
    }
}
