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

// NodeRoleFlags describes which responsibilities a node should perform.
type NodeRoleFlags struct {
	BuildManifest bool `json:"buildManifest,omitempty"`
	ExportData    bool `json:"exportData,omitempty"`
	ReceiveData   bool `json:"receiveData,omitempty"`
	RunCollective bool `json:"runCollective,omitempty"`
}

// RingPeerPlan describes the ring topology assigned to one node.
type RingPeerPlan struct {
	SelfNode       string `json:"selfNode"`
	PrevNode       string `json:"prevNode"`
	NextNode       string `json:"nextNode"`
	SelfEndpoint   string `json:"selfEndpoint,omitempty"`
	PrevEndpoint   string `json:"prevEndpoint,omitempty"`
	NextEndpoint   string `json:"nextEndpoint,omitempty"`
	Rank           int32  `json:"rank"`
	WorldSize      int32  `json:"worldSize"`
	IterationCount int32  `json:"iterationCount"`
}

// CollectivePeerPlan describes one peer's role in a collective exchange.
type CollectivePeerPlan struct {
	NodeName    string      `json:"nodeName"`
	Endpoint    string      `json:"endpoint,omitempty"`
	Rank        int32       `json:"rank"`
	StagingPath string      `json:"stagingPath,omitempty"`
	OwnedRanges []ByteRange `json:"ownedRanges,omitempty"`
}

// CollectiveSpec describes the collective session and peer topology.
type CollectiveSpec struct {
	SessionID     string               `json:"sessionID,omitempty"`
	Mode          CollectiveMode       `json:"mode"`
	Ring          *RingPeerPlan        `json:"ring,omitempty"`
	Peers         []CollectivePeerPlan `json:"peers,omitempty"`
	TransportHint string               `json:"transportHint,omitempty"`
}

// WarmupExecutionPlan 表示控制面下发给节点的最终执行对象。
type WarmupExecutionPlan struct {
	PlanID             string          `json:"planID"`
	TaskID             string          `json:"taskID"`
	ArtifactKey        string          `json:"artifactKey"`
	ArtifactType       ArtifactType    `json:"artifactType"`
	TargetNode         string          `json:"targetNode"`
	TargetFinalPath    string          `json:"targetFinalPath"`
	EnableChunkCRC32C  bool            `json:"enableChunkCRC32C"`
	PublishAsSource    bool            `json:"publishAsSource"`
	DistributionPlanID string          `json:"distributionPlanID,omitempty"`
	RoleFlags          NodeRoleFlags   `json:"roleFlags,omitempty"`
	CollectiveSpec     CollectiveSpec  `json:"collectiveSpec,omitempty"`
	LogicalManifest    LogicalManifest `json:"logicalManifest"`
	TransferSpec       TransferSpec    `json:"transferSpec"`
}