"""
File Service
Handles file uploads and management
"""

from typing import Dict, Any
from pathlib import Path
import uuid

class FileService:
    def __init__(self):
        self.upload_path = Path("uploads/logos")
        self.upload_path.mkdir(parents=True, exist_ok=True)
    
    async def save_logo(self, file) -> Dict[str, Any]:
        """
        Save uploaded logo file
        """
        try:
            # Generate unique filename
            file_extension = file.filename.split('.')[-1] if '.' in file.filename else 'png'
            unique_filename = f"{uuid.uuid4()}.{file_extension}"
            file_path = self.upload_path / unique_filename
            
            # Save file
            with open(file_path, "wb") as buffer:
                content = await file.read()
                buffer.write(content)
            
            return {
                "filename": unique_filename,
                "path": f"asset/img/{unique_filename}",
                "size": len(content)
            }
            
        except Exception as e:
            raise Exception(f"Logo save failed: {str(e)}")
    
    def get_logo_path(self, filename: str) -> Path:
        """
        Get logo file path
        """
        return self.upload_path / filename