/*
 * 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.
 */

package types

// RDMAConnectionInfo carries connection and memory-registration metadata.
type RDMAConnectionInfo struct {
	DeviceName string `json:"deviceName,omitempty"`
	QPN        uint32 `json:"qpn,omitempty"`
	PSN        uint32 `json:"psn,omitempty"`
	LID        uint16 `json:"lid,omitempty"`
	GID        string `json:"gid,omitempty"`
	RKey       uint32 `json:"rkey,omitempty"`
	Addr       uint64 `json:"addr,omitempty"`
	Length     uint64 `json:"length,omitempty"`
}

// RelayRDMAHint carries reusable RDMA session metadata for peer relay.
type RelayRDMAHint struct {
	SessionID      string             `json:"sessionID"`
	ConnectionInfo RDMAConnectionInfo `json:"connectionInfo"`
	Persistent     bool               `json:"persistent,omitempty"`
}

// OpenRDMAExportRequest asks the source side to expose a byte range via RDMA.
type OpenRDMAExportRequest struct {
	RootPath     string `json:"rootPath"`
	RelativePath string `json:"relativePath"`
	Offset       int64  `json:"offset"`
	Length       int64  `json:"length"`
}

// OpenRDMAExportResponse returns the RDMA export session metadata.
type OpenRDMAExportResponse struct {
	SessionID      string             `json:"sessionID"`
	TransportPath  TransportPath      `json:"transportPath"`
	SourceNode     string             `json:"sourceNode,omitempty"`
	ConnectionInfo RDMAConnectionInfo `json:"connectionInfo"`
	ExpectedCRC32C string             `json:"expectedCRC32C,omitempty"`
	Message        string             `json:"message,omitempty"`
}

// ConnectRDMAExportRequest asks a target to connect to an RDMA export session.
type ConnectRDMAExportRequest struct {
	SessionID      string             `json:"sessionID"`
	TargetNode     string             `json:"targetNode,omitempty"`
	ConnectionInfo RDMAConnectionInfo `json:"connectionInfo"`
	TimeoutSeconds int32              `json:"timeoutSeconds,omitempty"`
}

// ConnectRDMAExportResponse reports the result of export-session connection.
type ConnectRDMAExportResponse struct {
	SessionID     string        `json:"sessionID"`
	TransportPath TransportPath `json:"transportPath"`
	Message       string        `json:"message,omitempty"`
}

// UpdateRDMAExportRequest refreshes the exposed range for an RDMA session.
type UpdateRDMAExportRequest struct {
	SessionID string `json:"sessionID"`
	Offset    int64  `json:"offset"`
	Length    int64  `json:"length"`
}

// UpdateRDMAExportResponse returns refreshed export metadata for RDMA reads.
type UpdateRDMAExportResponse struct {
	SessionID      string             `json:"sessionID"`
	TransportPath  TransportPath      `json:"transportPath"`
	ConnectionInfo RDMAConnectionInfo `json:"connectionInfo"`
	ExpectedCRC32C string             `json:"expectedCRC32C,omitempty"`
	Message        string             `json:"message,omitempty"`
}

// CloseRDMAExportRequest asks the source to close an RDMA export session.
type CloseRDMAExportRequest struct {
	SessionID string `json:"sessionID"`
}

// CloseRDMAExportResponse confirms whether the export session was closed.
type CloseRDMAExportResponse struct {
	SessionID string `json:"sessionID"`
	Closed    bool   `json:"closed"`
}