package hubrpc

import (
	"context"

	clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types"
	"gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc"
)

type CacheSvc interface {
	CheckCache(ctx context.Context, req *CheckCache) (*CheckCacheResp, *rpc.CodeError)
	CacheGC(ctx context.Context, req *CacheGC) (*CacheGCResp, *rpc.CodeError)
}

// 获取Cache中文件列表
type CheckCache struct {
	UserSpace clitypes.UserSpaceDetail
}
type CheckCacheResp struct {
	FileHashes []clitypes.FileHash
}

func (c *Client) CheckCache(ctx context.Context, req *CheckCache) (*CheckCacheResp, *rpc.CodeError) {
	if c.fusedErr != nil {
		return nil, c.fusedErr
	}
	return rpc.UnaryClient[*CheckCacheResp](c.cli.CheckCache, ctx, req)
}
func (s *Server) CheckCache(ctx context.Context, req *rpc.Request) (*rpc.Response, error) {
	return rpc.UnaryServer(s.svrImpl.CheckCache, ctx, req)
}

// 清理Cache中不用的文件
type CacheGC struct {
	UserSpace  clitypes.UserSpaceDetail
	Availables []clitypes.FileHash
}
type CacheGCResp struct{}

func (c *Client) CacheGC(ctx context.Context, req *CacheGC) (*CacheGCResp, *rpc.CodeError) {
	if c.fusedErr != nil {
		return nil, c.fusedErr
	}
	return rpc.UnaryClient[*CacheGCResp](c.cli.CacheGC, ctx, req)
}
func (s *Server) CacheGC(ctx context.Context, req *rpc.Request) (*rpc.Response, error) {
	return rpc.UnaryServer(s.svrImpl.CacheGC, ctx, req)
}
