from datetime import UTC
from decimal import Decimal
from uuid import UUID, uuid4

from template_project.application.common.enums import ExperienceType
from template_project.application.vacancy.entity import Vacancy, VacancyEmbedding, VacancyId


def test_vacancy_factory_creates_valid_vacancy() -> None:
    vacancy = Vacancy.factory(
        position="Python Developer",
        from_salary=Decimal(100000),
        to_salary=Decimal(150000),
        experience_type=ExperienceType.BETWEEN_3_AND_6,
        description="Backend development",
        key_skills=["Python", "FastAPI"],
    )

    assert isinstance(vacancy.id, UUID)
    assert vacancy.position == "Python Developer"
    assert vacancy.from_salary == Decimal(100000)
    assert vacancy.to_salary == Decimal(150000)
    assert vacancy.experience_type == ExperienceType.BETWEEN_3_AND_6
    assert vacancy.description == "Backend development"
    assert vacancy.key_skills == ["Python", "FastAPI"]
    assert vacancy.deleted_at is None
    assert vacancy.created_at.tzinfo == UTC


def test_vacancy_salary_order() -> None:
    vacancy = Vacancy.factory(
        position="Developer",
        from_salary=Decimal(100000),
        to_salary=Decimal(150000),
        experience_type=ExperienceType.BETWEEN_1_AND_3,
        description="Test",
        key_skills=[],
    )

    assert vacancy.from_salary <= vacancy.to_salary


def test_vacancy_equal_salaries() -> None:
    vacancy = Vacancy.factory(
        position="Developer",
        from_salary=Decimal(100000),
        to_salary=Decimal(100000),
        experience_type=ExperienceType.BETWEEN_1_AND_3,
        description="Test",
        key_skills=[],
    )

    assert vacancy.from_salary == vacancy.to_salary


def test_vacancy_empty_key_skills() -> None:
    vacancy = Vacancy.factory(
        position="Developer",
        from_salary=Decimal(100000),
        to_salary=Decimal(150000),
        experience_type=ExperienceType.NO_EXPERIENCE,
        description="Test",
        key_skills=[],
    )

    assert vacancy.key_skills == []


def test_vacancy_embedding_vector_dimension() -> None:
    vacancy_id = VacancyId(uuid4())
    vector = [0.1] * 384

    embedding = VacancyEmbedding.factory(
        vacancy_id=vacancy_id,
        vector=vector,
    )

    assert len(embedding.vector) == 384
    assert all(isinstance(x, float) for x in embedding.vector)


def test_vacancy_embedding_factory_creates_valid_embedding() -> None:
    vacancy_id = VacancyId(uuid4())
    vector = [0.1, 0.2, 0.3, 0.4, 0.5]

    embedding = VacancyEmbedding.factory(
        vacancy_id=vacancy_id,
        vector=vector,
    )

    assert isinstance(embedding.id, UUID)
    assert embedding.vacancy_id == vacancy_id
    assert embedding.vector == vector
    assert embedding.deleted_at is None
    assert embedding.created_at.tzinfo == UTC
