# -*- coding: utf-8 -*-
from __future__ import annotations

import logging

from hotpocket_backend.apps.saves.services import (
    SaveProcessorService as BackendSaveProcessorService,
)
from hotpocket_soa.dto.celery import AsyncResultOut
from hotpocket_soa.dto.saves import SaveOut

from .base import ProxyService, SOAError

LOGGER = logging.getLogger(__name__)


class SaveProcessorService(ProxyService):
    class SaveProcessorServiceError(SOAError):
        pass

    def __init__(self):
        super().__init__()
        self.backend_save_processor_service = BackendSaveProcessorService()

    def get_error_class(self) -> type[SOAError]:
        return self.SaveProcessorServiceError

    def schedule_process_save(self, *, save: SaveOut) -> AsyncResultOut:
        result = AsyncResultOut.model_validate(
            self.call(
                self.backend_save_processor_service,
                'schedule_process_save',
                pk=save.pk,
            ),
            from_attributes=True,
        )

        LOGGER.debug('Scheduled processing task: id=`%s`', result.id)

        return result
