package catalog

import (
	
	
	

	
)

// icebucket is a wrapper around an objstore.Bucket.
// Iceberg files are written with the full uri path s3://bucket-name/data-warehouse, gs://bucket-name/data-warehouse, /Users/username/Documents/data-warehouse
// icebucket is used to strip the full path from the object name when interacting with the bucket, since buckets are only pointed at the warehouse level.
type icebucket struct {
	bucket objstore.Bucket

	// prefix is the full path prefix of the data warehouse. Ex. s3://bucket-name/data-warehouse, gs://bucket-name/data-warehouse, /Users/username/Documents/data-warehouse
	prefix string
}

// NewIcebucket creates a new icebucket with the given prefix and bucket.
// The warehouseURI is used to strip the full path of the data warehouse from the object name.
func ( string,  objstore.Bucket) *icebucket {
	return &icebucket{
		bucket: ,
		prefix: ,
	}
}

// Upload the contents of the reader as an object into the bucket.
// Upload should be idempotent.
func ( *icebucket) ( context.Context,  string,  io.Reader) error {
	return .bucket.Upload(, strings.TrimPrefix(, .prefix), )
}

// Delete removes the object with the given name.
// If object does not exist in the moment of deletion, Delete should throw error.
func ( *icebucket) ( context.Context,  string) error {
	// Strip the prefix from the name if one exists.
	return .bucket.Delete(, strings.TrimPrefix(, .prefix))
}

func ( *icebucket) () string { return .bucket.Name() }

func ( *icebucket) () error { return .bucket.Close() }

func ( *icebucket) ( context.Context,  string,  func(string) error,  ...objstore.IterOption) error {
	return .bucket.Iter(, strings.TrimPrefix(, .prefix), , ...)
}

// Get returns a reader for the given object name.
func ( *icebucket) ( context.Context,  string) (io.ReadCloser, error) {
	return .bucket.Get(, strings.TrimPrefix(, .prefix))
}

// GetRange returns a new range reader for the given object name and range.
func ( *icebucket) ( context.Context,  string, ,  int64) (io.ReadCloser, error) {
	return .bucket.GetRange(, strings.TrimPrefix(, .prefix), , )
}

// Exists checks if the given object exists in the bucket.
func ( *icebucket) ( context.Context,  string) (bool, error) {
	return .bucket.Exists(, strings.TrimPrefix(, .prefix))
}

// IsObjNotFoundErr returns true if error means that object is not found. Relevant to Get operations.
func ( *icebucket) ( error) bool { return .bucket.IsObjNotFoundErr() }

// IsAccessDeniedErr returns true if access to object is denied.
func ( *icebucket) ( error) bool { return .bucket.IsAccessDeniedErr() }

// Attributes returns information about the specified object.
func ( *icebucket) ( context.Context,  string) (objstore.ObjectAttributes, error) {
	return .bucket.Attributes(, strings.TrimPrefix(, .prefix))
}