from event_manager_api.shared import (
    EventPublishDetailDto,
    PublicationHistoryDto,
)
from model import EventPublishDetail


class EventPublishDetailMapper(object):
    @staticmethod
    def map(publish_detail: EventPublishDetail) -> EventPublishDetailDto:
        publication_history = []
        for history in publish_detail.publication_history:
            publication_history.append(
                PublicationHistoryDto(
                    created_at=history.created_at,
                    action=history.action,
                )
            )

        return EventPublishDetailDto(
            id=publish_detail.id,
            external_code=publish_detail.external_code,
            event=publish_detail.event,
            acked_at=publish_detail.acked_at,
            next_retry_at=publish_detail.next_retry_at,
            abandoned_at=publish_detail.abandoned_at,
            publication_history=publication_history,
            fifo=publish_detail.fifo,
            target=publish_detail.target,
        )
