package com.tuoheng.controller;

import com.tuoheng.service.ThirdService;
import com.tuoheng.until.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 第三方请求响应 前端控制器
 *
 * @Author xiaoying
 * @Date 2023/3/8 9:01
 */
@RestController
@RequestMapping("/third")
@Slf4j
public class ThirdController {

    @Autowired
    private ThirdService thirdService;


    /**
     * 通过clientId登录
     * @param clientId
     * @return
     */
    @GetMapping("/authorize")
    public JsonResult authorize(String clientId) {
        return thirdService.authorize(clientId);
    }

    /**
     * 机场平台跳转接口
     *
     */
    @CrossOrigin(origins = "https://airport.t-aaron.com")
    @GetMapping(value = "/redirect")
    public void airportRedirect(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        log.info("访问airport");
        resp.sendRedirect("https://airport.t-aaron.com/transfer");
    }

    /**
     * 城管平台跳转接口
     *
     */
    @CrossOrigin(origins = "https://telecomumale.t-aaron.com")
    @GetMapping(value = "/telecomumaleRedirect")
    public void redirect(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        resp.sendRedirect("https://telecomumale.t-aaron.com/transfer");
    }
}
