/*
 * Copyright (c) 2026 Huawei Technologies Co., Ltd.
 * openFuyao is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

//go:build !linux || !cgo || !rdma_native

// Package rdmaffi provides the platform-dependent RDMA engine bindings.
package rdmaffi

import (
	"fmt"

	sharedtypes "github.com/openfuyao/weight-dispatcher/pkg/types"
)

// Version reports the stub engine version string.
func Version() string {
	return "rdma-engine/unavailable"
}

// Init reports stub initialization failure for unsupported platforms.
func Init() int {
	return -1
}

// Available reports whether the RDMA engine is usable on this platform.
func Available() bool {
	return false
}

// LastError returns the reason the RDMA engine is unavailable.
func LastError() string {
	return "rdma-engine unavailable"
}

// SelfTest reports stub self-test failure for unsupported platforms.
func SelfTest() int {
	return -1
}

// PrepareDirectPull reports stub preparation failure for direct pull mode.
func PrepareDirectPull() int {
	return -1
}

// PrepareRing reports stub preparation failure for ring collective mode.
func PrepareRing(_, _ uint32) int {
	return -1
}

// ExecuteDirectPull reports that direct pull is unavailable on this platform.
func ExecuteDirectPull(_ sharedtypes.TransferSpec) (sharedtypes.TransferResult, error) {
	return sharedtypes.TransferResult{}, fmt.Errorf("rdma engine direct pull unavailable on this platform")
}

// OpenExportSession reports that RDMA export open is unavailable on this platform.
func OpenExportSession(_ sharedtypes.OpenRDMAExportRequest) (sharedtypes.OpenRDMAExportResponse, error) {
	return sharedtypes.OpenRDMAExportResponse{}, fmt.Errorf("rdma engine export open unavailable on this platform")
}

// ConnectExportSession reports that RDMA export connect is unavailable on this platform.
func ConnectExportSession(_ sharedtypes.ConnectRDMAExportRequest) (sharedtypes.ConnectRDMAExportResponse, error) {
	return sharedtypes.ConnectRDMAExportResponse{}, fmt.Errorf("rdma engine export connect unavailable on this platform")
}

// UpdateExportSession reports that RDMA export update is unavailable on this platform.
func UpdateExportSession(_ sharedtypes.UpdateRDMAExportRequest) (sharedtypes.UpdateRDMAExportResponse, error) {
	return sharedtypes.UpdateRDMAExportResponse{}, fmt.Errorf("rdma engine export update unavailable on this platform")
}

// CloseExportSession reports that RDMA export close is unavailable on this platform.
func CloseExportSession(_ sharedtypes.CloseRDMAExportRequest) (sharedtypes.CloseRDMAExportResponse, error) {
	return sharedtypes.CloseRDMAExportResponse{}, fmt.Errorf("rdma engine export close unavailable on this platform")
}

// PreferredTransport reports the fallback transport used by the stub engine.
func PreferredTransport() sharedtypes.TransportPath {
	return sharedtypes.TransportPathTCPFallback
}