"""ARR-owned orchestration for validate-before-write delivery ingestion."""

from __future__ import annotations

from arr_ingestion.repository import IngestionOutcome, IngestionRepository
from arr_ingestion.validation import DeliveryValidator


class IngestionService:
    def __init__(
        self,
        validator: DeliveryValidator,
        repository: IngestionRepository,
    ) -> None:
        self._validator = validator
        self._repository = repository

    def ingest(self, raw_envelope: bytes) -> IngestionOutcome:
        verified = self._validator.validate(raw_envelope)
        return self._repository.commit_delivery(verified)
