# Familiar - Self-Hosted AI Companion Platform
# Copyright (c) 2026 George Scott Foley
# ORCID: 0009-0006-4957-0540
# Email: Georgescottfoley@proton.me
# Licensed under the MIT License - see LICENSE file for details

"""Tests for the three new job classes: Security Analyst, OSINT Researcher, Network Admin."""

import pytest

import familiar.jobs.network_admin  # noqa: F401
import familiar.jobs.osint_researcher  # noqa: F401

# Ensure all job classes are registered by importing their modules
import familiar.jobs.security_analyst  # noqa: F401

# ---------------------------------------------------------------------------
# Security Analyst
# ---------------------------------------------------------------------------


class TestSecurityAnalyst:
    def test_security_analyst_registered(self):
        from familiar.jobs import get_job_class

        jc = get_job_class("security_analyst")
        assert jc is not None
        assert jc.key == "security_analyst"

    def test_security_analyst_workspace_has_overview_cards(self):
        from familiar.jobs import get_job_class

        jc = get_job_class("security_analyst")
        cards = jc.workspace.get("overview", {}).get("cards", [])
        assert len(cards) >= 4
        for card in cards:
            assert "key" in card
            assert "label" in card
            assert "source" in card
            assert "metric" in card

    def test_security_analyst_workspace_sources(self):
        from familiar.jobs import get_job_class

        jc = get_job_class("security_analyst")
        cards = jc.workspace.get("overview", {}).get("cards", [])
        for card in cards:
            source = card.get("source", "")
            assert isinstance(source, str)
            assert len(source) > 0

    def test_security_analyst_has_6_species_flavors(self):
        from familiar.jobs import get_job_class

        jc = get_job_class("security_analyst")
        assert len(jc.species_flavor) == 6


# ---------------------------------------------------------------------------
# OSINT Researcher
# ---------------------------------------------------------------------------


class TestOsintResearcher:
    def test_osint_researcher_registered(self):
        from familiar.jobs import get_job_class

        jc = get_job_class("osint_researcher")
        assert jc is not None
        assert jc.key == "osint_researcher"

    def test_osint_researcher_workspace_has_sections(self):
        from familiar.jobs import get_job_class

        jc = get_job_class("osint_researcher")
        sections = jc.workspace.get("sections", [])
        assert len(sections) >= 3

    def test_osint_researcher_species_flavors(self):
        from familiar.jobs import get_job_class

        jc = get_job_class("osint_researcher")
        assert len(jc.species_flavor) == 6

    def test_osint_researcher_prompt_mentions_authorization(self):
        from familiar.jobs import get_job_class

        jc = get_job_class("osint_researcher")
        assert "authoriz" in jc.prompt_fragment.lower()


# ---------------------------------------------------------------------------
# Network Admin
# ---------------------------------------------------------------------------


class TestNetworkAdmin:
    def test_network_admin_registered(self):
        from familiar.jobs import get_job_class

        jc = get_job_class("network_admin")
        assert jc is not None
        assert jc.key == "network_admin"

    def test_network_admin_workspace_sections(self):
        from familiar.jobs import get_job_class

        jc = get_job_class("network_admin")
        sections = jc.workspace.get("sections", [])
        assert len(sections) >= 3

    def test_network_admin_workspace_card_sources(self):
        from familiar.jobs import get_job_class

        jc = get_job_class("network_admin")
        cards = jc.workspace.get("overview", {}).get("cards", [])
        allowed_sources = {"netdata", "uptime_kuma"}
        for card in cards:
            source = card.get("source", "")
            assert source in allowed_sources, (
                f"Card '{card.get('key')}' has unexpected source '{source}'. "
                f"Expected one of: {allowed_sources}"
            )

    def test_network_admin_has_quick_actions(self):
        from familiar.jobs import get_job_class

        jc = get_job_class("network_admin")
        quick_actions = jc.workspace.get("quick_actions", [])
        assert len(quick_actions) >= 3
