from application.model import TotaledMessage
from application.repository.api import APIRepository
from typing import Optional
from .dto import GetTotaledMessageRequest


class GetTotaledMessageInteractor(object):
    def __init__(
        self,                       # type: GetTotaledMessageInteractor
        api_repository,             # type: APIRepository
        partner_has_endpoint,       # type: bool
    ):
        # type: (...) -> None

        self.api_repository = api_repository
        self.partner_has_endpoint = partner_has_endpoint

    def get_totaled_message(
        self,           # type: GetTotaledMessageInteractor
        request,        # type: GetTotaledMessageRequest
    ):
        # type: (...) -> Optional[TotaledMessage]

        if not self.partner_has_endpoint:
            return None

        return self.api_repository.get_totaled_message(
            pos_id=request.pos_id,
            customer_id=request.customer_id,
        )
