package files

import (
	"context"
	"os"
	"testing"
)

// TestStoreImplementsFileStorer is a compile-time assertion that *Store
// satisfies the FileStorer interface.
func TestStoreImplementsFileStorer(t *testing.T) {
	var _ FileStorer = (*Store)(nil)
}

// TestNewStore_SkipIfNoEndpoint verifies that NewStore returns a non-nil client
// when S3_ENDPOINT is configured. The test is skipped in CI / local dev unless
// a real MinIO instance is running and S3_ENDPOINT is set.
func TestNewStore_SkipIfNoEndpoint(t *testing.T) {
	endpoint := os.Getenv("S3_ENDPOINT")
	if endpoint == "" {
		t.Skip("S3_ENDPOINT not set — skipping live NewStore test")
	}

	bucket := os.Getenv("S3_BUCKET")
	if bucket == "" {
		bucket = "xtablo-dev"
	}
	region := os.Getenv("S3_REGION")
	if region == "" {
		region = "us-east-1"
	}
	accessKey := os.Getenv("S3_ACCESS_KEY")
	if accessKey == "" {
		accessKey = "minioadmin"
	}
	secretKey := os.Getenv("S3_SECRET_KEY")
	if secretKey == "" {
		secretKey = "minioadmin"
	}

	store, err := NewStore(context.Background(), endpoint, bucket, region, accessKey, secretKey, true)
	if err != nil {
		t.Fatalf("NewStore: %v", err)
	}
	if store == nil {
		t.Fatal("NewStore returned nil store without error")
	}
	if store.client == nil {
		t.Fatal("NewStore returned store with nil S3 client")
	}
}
