from datetime import UTC, datetime
from decimal import Decimal
from typing import NewType, Self
from uuid import UUID

from uuid_utils.compat import uuid7

from template_project.application.common.entity import Entity, to_entity
from template_project.application.common.enums import ExperienceType

VacancyId = NewType("VacancyId", UUID)
VacancyEmbeddingId = NewType("VacancyEmbeddingId", UUID)


@to_entity
class Vacancy(Entity[VacancyId]):
    position: str
    from_salary: Decimal
    to_salary: Decimal
    experience_type: ExperienceType
    description: str
    key_skills: list[str]

    @classmethod
    def factory(
        cls,
        position: str,
        from_salary: Decimal,
        to_salary: Decimal,
        experience_type: ExperienceType,
        description: str,
        key_skills: list[str],
    ) -> Self:
        return cls(
            id=VacancyId(uuid7()),
            created_at=datetime.now(tz=UTC),
            position=position,
            from_salary=from_salary,
            to_salary=to_salary,
            experience_type=experience_type,
            description=description,
            key_skills=key_skills,
        )


@to_entity
class VacancyEmbedding(Entity[VacancyEmbeddingId]):
    vacancy_id: VacancyId
    vector: list[float]

    @classmethod
    def factory(
        cls,
        vacancy_id: VacancyId,
        vector: list[float],
    ) -> Self:
        return cls(
            id=VacancyEmbeddingId(uuid7()),
            created_at=datetime.now(tz=UTC),
            vacancy_id=vacancy_id,
            vector=vector,
        )
