"""
Tests to verify admin schemas split maintains backward compatibility.

All existing imports from backend.web.schemas.admin must continue to work.
"""

import pytest


class TestEnumImports:
    """All enums importable from backend.web.schemas.admin."""

    def test_document_status(self):
        from backend.web.schemas.admin import DocumentStatus
        assert DocumentStatus.PENDING == "pending"

    def test_auto_label_status(self):
        from backend.web.schemas.admin import AutoLabelStatus
        assert AutoLabelStatus.RUNNING == "running"

    def test_training_status(self):
        from backend.web.schemas.admin import TrainingStatus
        assert TrainingStatus.PENDING == "pending"

    def test_training_type(self):
        from backend.web.schemas.admin import TrainingType
        assert TrainingType.TRAIN == "train"

    def test_annotation_source(self):
        from backend.web.schemas.admin import AnnotationSource
        assert AnnotationSource.MANUAL == "manual"


class TestAuthImports:
    """Auth schemas importable."""

    def test_admin_token_create(self):
        from backend.web.schemas.admin import AdminTokenCreate
        token = AdminTokenCreate(name="test")
        assert token.name == "test"

    def test_admin_token_response(self):
        from backend.web.schemas.admin import AdminTokenResponse
        assert AdminTokenResponse is not None


class TestDocumentImports:
    """Document schemas importable."""

    def test_document_upload_response(self):
        from backend.web.schemas.admin import DocumentUploadResponse
        assert DocumentUploadResponse is not None

    def test_document_item(self):
        from backend.web.schemas.admin import DocumentItem
        assert DocumentItem is not None

    def test_document_list_response(self):
        from backend.web.schemas.admin import DocumentListResponse
        assert DocumentListResponse is not None

    def test_document_detail_response(self):
        from backend.web.schemas.admin import DocumentDetailResponse
        assert DocumentDetailResponse is not None

    def test_document_stats_response(self):
        from backend.web.schemas.admin import DocumentStatsResponse
        assert DocumentStatsResponse is not None


class TestAnnotationImports:
    """Annotation schemas importable."""

    def test_bounding_box(self):
        from backend.web.schemas.admin import BoundingBox
        bb = BoundingBox(x=0, y=0, width=100, height=50)
        assert bb.width == 100

    def test_annotation_create(self):
        from backend.web.schemas.admin import AnnotationCreate
        assert AnnotationCreate is not None

    def test_annotation_update(self):
        from backend.web.schemas.admin import AnnotationUpdate
        assert AnnotationUpdate is not None

    def test_annotation_item(self):
        from backend.web.schemas.admin import AnnotationItem
        assert AnnotationItem is not None

    def test_annotation_response(self):
        from backend.web.schemas.admin import AnnotationResponse
        assert AnnotationResponse is not None

    def test_annotation_list_response(self):
        from backend.web.schemas.admin import AnnotationListResponse
        assert AnnotationListResponse is not None

    def test_annotation_lock_request(self):
        from backend.web.schemas.admin import AnnotationLockRequest
        assert AnnotationLockRequest is not None

    def test_annotation_lock_response(self):
        from backend.web.schemas.admin import AnnotationLockResponse
        assert AnnotationLockResponse is not None

    def test_auto_label_request(self):
        from backend.web.schemas.admin import AutoLabelRequest
        assert AutoLabelRequest is not None

    def test_auto_label_response(self):
        from backend.web.schemas.admin import AutoLabelResponse
        assert AutoLabelResponse is not None

    def test_annotation_verify_request(self):
        from backend.web.schemas.admin import AnnotationVerifyRequest
        assert AnnotationVerifyRequest is not None

    def test_annotation_verify_response(self):
        from backend.web.schemas.admin import AnnotationVerifyResponse
        assert AnnotationVerifyResponse is not None

    def test_annotation_override_request(self):
        from backend.web.schemas.admin import AnnotationOverrideRequest
        assert AnnotationOverrideRequest is not None

    def test_annotation_override_response(self):
        from backend.web.schemas.admin import AnnotationOverrideResponse
        assert AnnotationOverrideResponse is not None


class TestTrainingImports:
    """Training schemas importable."""

    def test_training_config(self):
        from backend.web.schemas.admin import TrainingConfig
        config = TrainingConfig()
        assert config.epochs == 100

    def test_training_task_create(self):
        from backend.web.schemas.admin import TrainingTaskCreate
        assert TrainingTaskCreate is not None

    def test_training_task_item(self):
        from backend.web.schemas.admin import TrainingTaskItem
        assert TrainingTaskItem is not None

    def test_training_task_list_response(self):
        from backend.web.schemas.admin import TrainingTaskListResponse
        assert TrainingTaskListResponse is not None

    def test_training_task_detail_response(self):
        from backend.web.schemas.admin import TrainingTaskDetailResponse
        assert TrainingTaskDetailResponse is not None

    def test_training_task_response(self):
        from backend.web.schemas.admin import TrainingTaskResponse
        assert TrainingTaskResponse is not None

    def test_training_log_item(self):
        from backend.web.schemas.admin import TrainingLogItem
        assert TrainingLogItem is not None

    def test_training_logs_response(self):
        from backend.web.schemas.admin import TrainingLogsResponse
        assert TrainingLogsResponse is not None

    def test_export_request(self):
        from backend.web.schemas.admin import ExportRequest
        assert ExportRequest is not None

    def test_export_response(self):
        from backend.web.schemas.admin import ExportResponse
        assert ExportResponse is not None

    def test_training_document_item(self):
        from backend.web.schemas.admin import TrainingDocumentItem
        assert TrainingDocumentItem is not None

    def test_training_documents_response(self):
        from backend.web.schemas.admin import TrainingDocumentsResponse
        assert TrainingDocumentsResponse is not None

    def test_model_metrics(self):
        from backend.web.schemas.admin import ModelMetrics
        assert ModelMetrics is not None

    def test_training_model_item(self):
        from backend.web.schemas.admin import TrainingModelItem
        assert TrainingModelItem is not None

    def test_training_models_response(self):
        from backend.web.schemas.admin import TrainingModelsResponse
        assert TrainingModelsResponse is not None

    def test_training_history_item(self):
        from backend.web.schemas.admin import TrainingHistoryItem
        assert TrainingHistoryItem is not None


class TestDatasetImports:
    """Dataset schemas importable."""

    def test_dataset_create_request(self):
        from backend.web.schemas.admin import DatasetCreateRequest
        assert DatasetCreateRequest is not None

    def test_dataset_document_item(self):
        from backend.web.schemas.admin import DatasetDocumentItem
        assert DatasetDocumentItem is not None

    def test_dataset_response(self):
        from backend.web.schemas.admin import DatasetResponse
        assert DatasetResponse is not None

    def test_dataset_detail_response(self):
        from backend.web.schemas.admin import DatasetDetailResponse
        assert DatasetDetailResponse is not None

    def test_dataset_list_item(self):
        from backend.web.schemas.admin import DatasetListItem
        assert DatasetListItem is not None

    def test_dataset_list_response(self):
        from backend.web.schemas.admin import DatasetListResponse
        assert DatasetListResponse is not None

    def test_dataset_train_request(self):
        from backend.web.schemas.admin import DatasetTrainRequest
        assert DatasetTrainRequest is not None


class TestForwardReferences:
    """Forward references resolve correctly."""

    def test_document_detail_has_annotation_items(self):
        from backend.web.schemas.admin import DocumentDetailResponse
        fields = DocumentDetailResponse.model_fields
        assert "annotations" in fields
        assert "training_history" in fields

    def test_dataset_train_request_has_config(self):
        from backend.web.schemas.admin import DatasetTrainRequest, TrainingConfig
        req = DatasetTrainRequest(name="test", config=TrainingConfig())
        assert req.config.epochs == 100
