package services

/*
import (
	"fmt"
	"time"

	cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"

	stgglb "gitlink.org.cn/cloudream/jcs-pub/common/globals"
	hubmq "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/mq/hub"
	coormq "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/mq/coordinator"
	"gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory"
)

type CacheService struct {
	*Service
}

func (svc *Service) CacheSvc() *CacheService {
	return &CacheService{Service: svc}
}

func (svc *CacheService) StartCacheMovePackage(userID cdssdk.UserID, packageID cdssdk.PackageID, stgID cdssdk.StorageID) (cdssdk.HubID, string, error) {
	coorCli, err := stgglb.CoordinatorMQPool.Acquire()
	if err != nil {
		return 0, "", fmt.Errorf("new coordinator client: %w", err)
	}
	defer stgglb.CoordinatorMQPool.Release(coorCli)

	getStg, err := coorCli.GetStorageDetails(coormq.ReqGetStorageDetails([]cdssdk.StorageID{stgID}))
	if err != nil {
		return 0, "", fmt.Errorf("get storage detail: %w", err)
	}

	if !factory.GetBuilder(*getStg.Storages[0]).ShardStoreDesc().Enabled() {
		return 0, "", fmt.Errorf("shard storage is not enabled")
	}

	hubCli, err := stgglb.HubMQPool.Acquire(getStg.Storages[0].MasterHub.HubID)
	if err != nil {
		return 0, "", fmt.Errorf("new hub client: %w", err)
	}
	defer stgglb.HubMQPool.Release(hubCli)

	startResp, err := hubCli.StartCacheMovePackage(hubmq.NewStartCacheMovePackage(userID, packageID, stgID))
	if err != nil {
		return 0, "", fmt.Errorf("start cache move package: %w", err)
	}

	return getStg.Storages[0].MasterHub.HubID, startResp.TaskID, nil
}

func (svc *CacheService) WaitCacheMovePackage(hubID cdssdk.HubID, taskID string, waitTimeout time.Duration) (bool, error) {
	hubCli, err := stgglb.HubMQPool.Acquire(hubID)
	if err != nil {
		return true, fmt.Errorf("new hub client: %w", err)
	}
	defer stgglb.HubMQPool.Release(hubCli)

	waitResp, err := hubCli.WaitCacheMovePackage(hubmq.NewWaitCacheMovePackage(taskID, waitTimeout.Milliseconds()))
	if err != nil {
		return true, fmt.Errorf("wait cache move package: %w", err)
	}

	if !waitResp.IsComplete {
		return false, nil
	}

	if waitResp.Error != "" {
		return true, fmt.Errorf("%s", waitResp.Error)
	}

	return true, nil
}

func (svc *CacheService) CacheRemovePackage(packageID cdssdk.PackageID, stgID cdssdk.StorageID) error {
	coorCli, err := stgglb.CoordinatorMQPool.Acquire()
	if err != nil {
		return fmt.Errorf("new hub client: %w", err)
	}
	defer stgglb.CoordinatorMQPool.Release(coorCli)

	_, err = coorCli.CacheRemovePackage(coormq.ReqCacheRemoveMovedPackage(packageID, stgID))
	if err != nil {
		return fmt.Errorf("requesting to coordinator: %w", err)
	}

	return nil
}
*/
