import boto3
from typing import Optional

class S3StorageAdapter:
    """AWS S3 storage adapter."""

    def __init__(self, bucket: str, region: str):
        self.bucket = bucket
        self.region = region
        self.client = boto3.client('s3', region_name=region)

    async def upload(self, file_id: str, content: bytes) -> bool:
        try:
            self.client.put_object(Bucket=self.bucket, Key=file_id, Body=content)
            return True
        except Exception:
            return False

    async def download(self, file_id: str) -> Optional[bytes]:
        try:
            response = self.client.get_object(Bucket=self.bucket, Key=file_id)
            return response['Body'].read()
        except Exception:
            return None
