from collections.abc import Sequence
from typing import override

from template_project.adapters.ml_api_gateway import MlApiGateway, SuitableVacancyDs
from template_project.application.resume.entity import Resume, ResumePrediction
from template_project.application.resume.resume_prediction_generator import ResumePredictionGenerator
from template_project.application.vacancy.data_structure import SuitableVacancy


class DefaultResumePredictionGenerator(ResumePredictionGenerator):
    def __init__(self, ml_api_gateway: MlApiGateway) -> None:
        self._ml_api_gateway = ml_api_gateway

    @override
    async def generate(
        self,
        resume: Resume,
        suitable_vacancies: Sequence[SuitableVacancy],
    ) -> ResumePrediction:
        response = await self._ml_api_gateway.generate_resume_prediction(
            resume_id=resume.id,
            key_skills=resume.key_skills,
            suitable_vacancies=[
                SuitableVacancyDs(
                    vacancy_id=str(suitable_vacancy.vacancy.id),
                    from_salary=suitable_vacancy.vacancy.from_salary,
                    to_salary=suitable_vacancy.vacancy.to_salary,
                    key_skills=suitable_vacancy.vacancy.key_skills,
                    resume_similarity=suitable_vacancy.resume_similarity,
                )
                for suitable_vacancy in suitable_vacancies
            ],
        )
        return ResumePrediction.factory(
            resume_id=resume.id,
            from_salary=response.salary_from,
            to_salary=response.salary_to,
            recommended_skills=response.recommended_skills,
        )
