package com.hotent.dataMiddlePlatform.controller;

import com.alibaba.fastjson.JSON;
import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.model.CommonResult;
import com.hotent.baseInfo.resp.AuditedUnitDetailResp;
import com.hotent.dataMiddlePlatform.manager.DataMiddlePlatformManager;
import com.hotent.uc.params.org.OrgVo;
import com.integration.oauth2.sdk.OAuth2Client;
import com.integration.oauth2.sdk.method.OAuth2ToMethod;
import com.integration.oauth2.sdk.model.Org;
import com.integration.oauth2.sdk.model.UserDetail;
import com.integration.oauth2.sdk.model.UserInfo;
import com.integration.oauth2.sdk.response.AccessTokenResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 *@author: zhao yue yue
 *@create: 2025-11-06 11:35
 */
@Api(tags = "中台组织用户数据同步")
@RestController
@RequestMapping("/api/data-middle-platform")
public class DataMiddlePlatformController {

    @Autowired
    private DataMiddlePlatformManager dataMiddlePlatformManager;



    @GetMapping("/sync")
    @ApiOperation(value = "同步中台数据", notes = "初始化同步中台数据")
    public CommonResult<String> sync() {
        try {
            dataMiddlePlatformManager.sync();
            return CommonResult.<String>ok().message("同步成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    @GetMapping("/sso/dmp")
    @ApiOperation(value = "中台系统单点登录", notes = "中台系统单点登录")
    public ResponseEntity<?> ssoDataMiddlePlatform(
            @ApiParam(name="code",value="随机码", required = true)
            @RequestParam (value="code",required=true) String code) {
        try {
            return dataMiddlePlatformManager.ssoDataMiddlePlatform(code);
            //dataMiddlePlatformManager.sync();
        } catch (Exception e) {
            throw new RuntimeException("中台单点登录失败");
        }
    }



}
