23 lines
660 B
Python
23 lines
660 B
Python
from dataclasses import dataclass
|
|
|
|
from .kab_ingestion.domain.models import SourceDocument
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ValidationReport:
|
|
valid: bool
|
|
errors: tuple[str, ...]
|
|
|
|
|
|
def validate_document(document: SourceDocument) -> ValidationReport:
|
|
errors: list[str] = []
|
|
if not document.identifier.strip():
|
|
errors.append("identifier is required")
|
|
if not document.title.strip():
|
|
errors.append("title is required")
|
|
if not document.body.strip():
|
|
errors.append("body is required")
|
|
if not document.source.strip():
|
|
errors.append("source is required")
|
|
return ValidationReport(not errors, tuple(errors))
|