package gcs

import (
	"context"

	"cloud.google.com/go/iam"
	"cloud.google.com/go/storage"
)

type CloudStorageClient interface {
	Bucket(name string) BucketHandle
}

type BucketHandle interface {
	Create(ctx context.Context, projectID string, attrs *storage.BucketAttrs) (err error)
	Object(name string) *storage.ObjectHandle
	Objects(ctx context.Context, q *storage.Query) *storage.ObjectIterator
	Attrs(ctx context.Context) (attrs *storage.BucketAttrs, err error)
	Update(ctx context.Context, attrs storage.BucketAttrsToUpdate) (attrsOut *storage.BucketAttrs, err error)
	IAMV3() IamHandle3
}

type IamHandle3 interface {
	Policy(ctx context.Context) (*iam.Policy3, error)
	SetPolicy(ctx context.Context, policy *iam.Policy3) error
}

// wrapper
type StorageClientWarp struct {
	*storage.Client
}

// just delegate to the actual client
func (c StorageClientWarp) Bucket(name string) BucketHandle {
	return BucketHandleWarp{c.Client.Bucket(name)}
}

type BucketHandleWarp struct {
	*storage.BucketHandle
}

func (c BucketHandleWarp) IAMV3() IamHandle3 {
	return c.IAM().V3()
}
