"""Unit tests for submit readiness validation (no database)."""

from __future__ import annotations

import unittest

from src.initiative_db.submission_readiness import (
    ApplicationSubmissionNotReadyError,
    collect_submission_readiness_gaps,
)

from tests.fixtures.minimal_submit_bundle import minimal_tabs_bundle


class SubmissionReadinessTests(unittest.TestCase):
    def test_minimal_tabs_with_technical_evidence_ok(self) -> None:
        tabs = minimal_tabs_bundle()
        gaps = collect_submission_readiness_gaps(
            tabs,
            {"research": False, "textbook": False, "technical": True},
        )
        self.assertEqual(gaps, [])

    def test_missing_evidence_fails(self) -> None:
        tabs = minimal_tabs_bundle()
        gaps = collect_submission_readiness_gaps(
            tabs,
            {"research": False, "textbook": False, "technical": False},
        )
        self.assertTrue(any("Nhóm 1" in g for g in gaps))

    def test_missing_honesty_flags(self) -> None:
        tabs = minimal_tabs_bundle()
        tabs["report"]["honestyConfirmed"] = False
        gaps = collect_submission_readiness_gaps(
            tabs,
            {"research": False, "textbook": False, "technical": True},
        )
        self.assertTrue(any("Báo cáo" in g and "cam kết" in g for g in gaps))

    def test_exception_carries_missing(self) -> None:
        exc = ApplicationSubmissionNotReadyError(["a", "b"])
        self.assertEqual(exc.missing, ["a", "b"])


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