package com.usky.issue.controller.web;

import com.usky.common.core.bean.ApiResult;
import com.usky.common.security.utils.SecurityUtils;
import com.usky.issue.service.vo.CloudConfigResponse;
import com.usky.issue.service.vo.CloudConfigSaveRequest;
import com.usky.issue.service.vo.CloudConnectionTestRequest;
import com.usky.issue.service.vo.CloudConnectionTestResponse;
import com.usky.issue.service.vo.CloudDisableResponse;
import com.usky.issue.service.CloudConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 云平台配置接口
 *
 * @author fyc
 * @date 2026-05-21
 */
@Validated
@RestController
@RequestMapping("/cloud")
public class CloudConfigController {

    @Autowired
    private CloudConfigService cloudConfigService;

    /**
     * 获取云平台配置
     */
    @GetMapping("/config")
    public ApiResult<CloudConfigResponse> getConfig() {
        return ApiResult.success(cloudConfigService.getConfig());
    }

    /**
     * 保存、修改云平台配置
     */
    @PutMapping("/config")
    public ApiResult<CloudConfigResponse> saveConfig(
            @Valid @RequestBody CloudConfigSaveRequest request) {
        return ApiResult.success(cloudConfigService.saveConfig(request));
    }


    /**
     * 分层连通性测试：网络层 → 认证层 → 租户层
     */
    @PostMapping("/config/testConnection")
    public ApiResult<CloudConnectionTestResponse> testConnection(
            @Valid @RequestBody CloudConnectionTestRequest request
    ) {
        return ApiResult.success(cloudConfigService.testConnection(request));
    }

    /**
     * 启用/禁用云平台（status: 0-禁用, 1-启用）
     */
    @PutMapping("/config/disable")
    public ApiResult<CloudDisableResponse> disable(@RequestParam Integer status) {
        return ApiResult.success(cloudConfigService.disable(status));
    }

}
