from pathlib import Path

from harbor.auth.client import create_authenticated_client
from harbor.storage.base import BaseStorage

BUCKET = "packages"


class SupabaseStorage(BaseStorage):
    async def upload_file(self, file_path: Path, remote_path: str) -> None:
        client = await create_authenticated_client()
        data = file_path.read_bytes()
        await client.storage.from_(BUCKET).upload(remote_path, data)

    async def download_file(self, remote_path: str, file_path: Path) -> None:
        client = await create_authenticated_client()
        data = await client.storage.from_(BUCKET).download(remote_path)
        file_path.parent.mkdir(parents=True, exist_ok=True)
        file_path.write_bytes(data)
