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

import "time"

// TaskHandle 是节点接受任务后的轻量响应。
type TaskHandle struct {
	TaskID     string `json:"taskID"`
	NodeName   string `json:"nodeName"`
	AcceptedAt int64  `json:"acceptedAt"`
}

// TaskStatus 表示节点任务状态。
type TaskStatus struct {
	TaskID             string              `json:"taskID"`
	Phase              WarmupTaskPhase     `json:"phase"`
	ProgressBytes      int64               `json:"progressBytes,omitempty"`
	ThroughputMBps     float64             `json:"throughputMBps,omitempty"`
	TransportPath      TransportPath       `json:"transportPath,omitempty"`
	Message            string              `json:"message,omitempty"`
	UpdatedAt          int64               `json:"updatedAt"`
	CachePath          string              `json:"cachePath,omitempty"`
	StartedAt          *time.Time          `json:"startedAt,omitempty"`
	FinishedAt         *time.Time          `json:"finishedAt,omitempty"`
	SolidifiedManifest *SolidifiedManifest `json:"solidifiedManifest,omitempty"`
}

// SubmitWarmupRequest 是节点侧提交接口输入。
type SubmitWarmupRequest struct {
	Plan WarmupExecutionPlan `json:"plan"`
}

// GetWarmupTaskStatusRequest 是节点侧状态查询输入。
type GetWarmupTaskStatusRequest struct {
	TaskID string `json:"taskID"`
}

// BuildManifestRequest 请求 source 节点生成轻量级逻辑 manifest。
type BuildManifestRequest struct {
	ArtifactKey    string         `json:"artifactKey"`
	Source         SourceEndpoint `json:"source"`
	ChunkSizeBytes int64          `json:"chunkSizeBytes"`
}

// BuildManifestResponse 返回 source 节点生成的逻辑 manifest。
type BuildManifestResponse struct {
	Manifest LogicalManifest `json:"manifest"`
}

// StatExportRequest 请求 source/export 侧返回文件大小。
type StatExportRequest struct {
	RootPath     string `json:"rootPath"`
	RelativePath string `json:"relativePath"`
}

// StatExportResponse 返回导出文件大小。
type StatExportResponse struct {
	SizeBytes int64 `json:"sizeBytes"`
}

// ReadChunkRequest 请求读取一个文件片段。
type ReadChunkRequest struct {
	RootPath     string `json:"rootPath"`
	RelativePath string `json:"relativePath"`
	Offset       int64  `json:"offset"`
	Length       int64  `json:"length"`
}

// ReadChunkResponse 返回读取到的字节块。
type ReadChunkResponse struct {
	Data   []byte `json:"data"`
	CRC32C string `json:"crc32c,omitempty"`
}