package com.ruoyi.ibs.app.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.ibs.app.domain.QyWxpropertiex;
import com.ruoyi.ibs.app.domain.UrlDTO;
import com.ruoyi.ibs.app.service.QYWeiXinManagerInfoService;
import com.ruoyi.ibs.app.service.WeiXinService;
import com.ruoyi.ibs.app.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

/**
 * @author 600477
 * @date 2023/11/9
 */
@Api(tags = "移动端企业微信相关服务")
@RequestMapping("/api/mobile/qy/weixin")
@RestController
public class QYWeiXinController {

    @Autowired
    private WeiXinService weiXinService;

    @Autowired
    private QYWeiXinManagerInfoService qyWeiXinManagerInfoService;

    @Autowired
    private QyWxpropertiex qyWeiXinProperties;


    @ApiOperation(value = "获取企业微信服务器ip")
    @GetMapping("/getIp")
    public AjaxResult getIp(String orgId) {
        return weiXinService.getIp(orgId);
    }


    @ApiOperation(value = "获取使用企业微信jdk的票据")
    @GetMapping("/ticket")
    public JsonResult getTicket(String qyUrl,String orgId) throws UnsupportedEncodingException {
        String url =  URLDecoder.decode(qyUrl, StandardCharsets.UTF_8.toString());
        return weiXinService.getTicketVo2(url,orgId);
    }

    @ApiOperation(value = "获取企业微信用户客户经理相关信息")
    @GetMapping("/userinfo")
    @Log(title = "企业微信登录")
    public AjaxResult getUserInfo(String code,String orgId) {
        return qyWeiXinManagerInfoService.getQYWeiXinUserInfo( code,orgId );
    }

    @ApiOperation(value = "获取企业微信相关参数")
    @GetMapping("/getQyApi")
    public AjaxResult getQyApi(String orgId) {
        return AjaxResult.success(qyWeiXinManagerInfoService.getQyApi2( orgId ));
    }

    @ApiOperation(value = "获取企业微信用户客户经理相关信息")
    @GetMapping("/getLoginUser")
    //生产要注解掉
    public AjaxResult getLogin(@RequestParam String userName) {
        return qyWeiXinManagerInfoService.getLogin( userName );
    }
}
