from pathlib import Path from pydantic import BaseModel, Field from core.base import TypedTransport from reporting.models import RenderedReport class FileTransportConfig(BaseModel): path: str = Field() append_extension: bool = Field(True) class FileTransport(TypedTransport[FileTransportConfig]): transport_type = "file" config_model = FileTransportConfig def publish_typed(self, rendered_report: RenderedReport, transport: FileTransportConfig) -> str: destination = Path(transport.path) if transport.append_extension and not destination.suffix: destination = destination.with_suffix(rendered_report.file_extension) destination.parent.mkdir(parents=True, exist_ok=True) destination.write_text(rendered_report.content, encoding="utf-8") return str(destination)