package cli

import (
	"context"

	"tsne.dev/hopper/internal/bunny"
)

// storageAPI is the full storage surface the dry-run decorator delegates to.
// Its read side (List) must stay real even under --dry-run; its
// write side (Upload/Delete) is what the decorator stubs. The real
// *bunny.Client satisfies this, as does the recording fake used in tests.
type storageAPI interface {
	Upload(ctx context.Context, path string, body []byte) error
	List(ctx context.Context, dir string) *bunny.Iterator
	Delete(ctx context.Context, path string) error
	DeleteDir(ctx context.Context, path string) error
}

func newStorageAPI(endpoint, zone, accessKey string) storageAPI {
	var api storageAPI = bunny.NewAPI(endpoint, zone, accessKey)
	if dryRun {
		api = dryRunStorageAPI{api}
	}
	return api
}

type dryRunStorageAPI struct {
	upstream storageAPI
}

func (api dryRunStorageAPI) List(ctx context.Context, dir string) *bunny.Iterator {
	return api.upstream.List(ctx, dir)
}

func (api dryRunStorageAPI) Upload(ctx context.Context, path string, body []byte) error {
	return nil
}

func (api dryRunStorageAPI) Delete(ctx context.Context, path string) error {
	return nil
}

func (api dryRunStorageAPI) DeleteDir(ctx context.Context, path string) error {
	return nil
}
