from __future__ import annotations

import unittest

from epione_templates import approval_summary, load_template_data
from epione_templates.product_verification import (
    APPROVED_PRODUCT_STATUS,
    product_approval_finding,
)


class ProductVerificationTests(unittest.TestCase):
    def test_current_v06_candidates_are_not_approved_defaults(self) -> None:
        summary = approval_summary(load_template_data())

        self.assertEqual(summary["approved_for_default"], 0)
        self.assertGreater(summary["blocked_or_pending"], 0)

    def test_verified_active_product_still_needs_required_fields(self) -> None:
        finding = product_approval_finding(
            {
                "library_id": "TEST_PRODUCT",
                "verification_status": APPROVED_PRODUCT_STATUS,
                "approved_for_default_yes_no": "YES",
            }
        )

        self.assertFalse(finding.approved_for_default)
        self.assertIn("missing verification fields", finding.reason)

    def test_verified_active_complete_product_can_be_default_candidate(self) -> None:
        finding = product_approval_finding(
            {
                "library_id": "TEST_PRODUCT",
                "verification_status": APPROVED_PRODUCT_STATUS,
                "verified_by": "Medical Director",
                "verified_date": "2026-05-02",
                "regulatory_source": "Health Canada DPD",
                "source_url": "https://example.invalid/source",
                "DIN_or_licence_number": "00000000",
                "manufacturer": "Example Manufacturer",
                "status": "ACTIVE",
                "last_checked": "2026-05-02",
                "clinic_stocked_yes_no": "YES",
                "approved_for_default_yes_no": "YES",
            }
        )

        self.assertTrue(finding.approved_for_default)


if __name__ == "__main__":
    unittest.main()
