from __future__ import annotations

import unittest

from epione_templates import load_template_data, validate_template_data


class ValidationTests(unittest.TestCase):
    def test_v06_data_passes_initial_schema_gate(self) -> None:
        errors = validate_template_data(load_template_data())

        self.assertEqual(errors, [])

    def test_all_procedure_forms_have_next_procedure_tokens_and_fields(self) -> None:
        data = load_template_data()
        required_keys = {
            "next_procedure_date",
            "next_procedure_medication_choice",
            "next_procedure_dose",
            "next_procedure_technique",
            "next_procedure_patient_position",
            "next_procedure_premedication",
            "next_procedure_pre_procedure_comments",
            "next_procedure_intra_procedure_comments",
            "next_procedure_post_procedure_comments",
        }

        for form in data["forms"]:
            if form.get("form_type") != "Procedure":
                continue
            field_keys = {field["key"] for field in form["fields"]}
            template = form.get("narrative_template") or form["template"]
            self.assertTrue(required_keys.issubset(field_keys), form["form_id"])
            self.assertIn("Recommended next procedure:", template, form["form_id"])
            for key in required_keys:
                self.assertIn("{{" + key + "}}", template, form["form_id"])


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