package repository

import (
	"context"
	"github.com/ocdp/cluster-service/internal/domain/entity"
	"k8s.io/apimachinery/pkg/api/resource"
)

type ResourceVector struct {
	CPU         resource.Quantity
	Memory      resource.Quantity
	GPU         int64
	GPUMemoryMB int64
}

type ResourceEstimate struct {
	Requests ResourceVector
	Limits   ResourceVector
}

// HelmClient Helm 客户端接口（Output Port）
type HelmClient interface {
	// Install 安装 Helm Chart
	Install(ctx context.Context, cluster *entity.Cluster, instance *entity.Instance) error

	// Upgrade 升级 Helm Release
	Upgrade(ctx context.Context, cluster *entity.Cluster, instance *entity.Instance) error

	// Uninstall 卸载 Helm Release
	Uninstall(ctx context.Context, cluster *entity.Cluster, releaseName, namespace string) error

	// Rollback 回滚 Helm Release
	Rollback(ctx context.Context, cluster *entity.Cluster, releaseName, namespace string, revision int) error

	// GetStatus 获取 Release 状态
	GetStatus(ctx context.Context, cluster *entity.Cluster, releaseName, namespace string) (*entity.Instance, error)

	// GetHistory 获取 Release 历史
	GetHistory(ctx context.Context, cluster *entity.Cluster, releaseName, namespace string) ([]*entity.ReleaseHistory, error)

	// List 列出集群中的所有 Releases
	List(ctx context.Context, cluster *entity.Cluster, namespace string) ([]*entity.Instance, error)

	// GetValues 获取 Release 的 values
	GetValues(ctx context.Context, cluster *entity.Cluster, releaseName, namespace string) (map[string]interface{}, error)

	// GetChartDefaultValues 从 chart 包中读取默认 values
	GetChartDefaultValues(chartPath string) (map[string]interface{}, error)

	// EstimateInstanceResources renders an instance chart with final values and sums Pod template resources.
	EstimateInstanceResources(ctx context.Context, cluster *entity.Cluster, instance *entity.Instance) (*ResourceEstimate, error)
}
