package com.usky.issue.service.vo;

import com.usky.issue.service.constant.CloudIntegrationConstants;
import lombok.Data;

/**
 * 连接测试内部结果（HTTP 客户端层）
 *
 * @author fyc
 * @date 2026-06-08
 */
@Data
public class CloudConnectionTestResult {

    private boolean success;
    private String message;
    /** 是否已到达云平台（HTTP/TCP 层可达） */
    private boolean networkReachable;
    /** 认证层是否通过 */
    private boolean authValid;
    /** 租户配置是否存在且启用 */
    private boolean tenantExists;
    /** 耗时（毫秒） */
    private Long costTime;

    public static CloudConnectionTestResult success(String message) {
        CloudConnectionTestResult result = new CloudConnectionTestResult();
        result.setSuccess(true);
        result.setMessage(message);
        result.setNetworkReachable(true);
        result.setAuthValid(true);
        result.setTenantExists(true);
        return result;
    }

    public static CloudConnectionTestResult fullSuccess(long costTime) {
        CloudConnectionTestResult result = success(CloudIntegrationConstants.MSG_CONNECTION_SUCCESS);
        result.setCostTime(costTime);
        return result;
    }

    public static CloudConnectionTestResult networkFailure(String message) {
        CloudConnectionTestResult result = new CloudConnectionTestResult();
        result.setSuccess(false);
        result.setMessage(message);
        result.setNetworkReachable(false);
        result.setAuthValid(false);
        result.setTenantExists(false);
        return result;
    }

    public static CloudConnectionTestResult authFailure(long costTime, String message) {
        CloudConnectionTestResult result = new CloudConnectionTestResult();
        result.setSuccess(false);
        result.setMessage(message);
        result.setNetworkReachable(true);
        result.setAuthValid(false);
        result.setTenantExists(false);
        result.setCostTime(costTime);
        return result;
    }

    public static CloudConnectionTestResult tenantMissing(long costTime) {
        CloudConnectionTestResult result = new CloudConnectionTestResult();
        result.setSuccess(false);
        result.setMessage(CloudIntegrationConstants.MSG_TENANT_CONFIG_MISSING);
        result.setNetworkReachable(true);
        result.setAuthValid(true);
        result.setTenantExists(false);
        result.setCostTime(costTime);
        return result;
    }

    public static CloudConnectionTestResult failure(boolean networkReachable, String message) {
        CloudConnectionTestResult result = new CloudConnectionTestResult();
        result.setSuccess(false);
        result.setMessage(message);
        result.setNetworkReachable(networkReachable);
        return result;
    }
}
