"""
Requirement Pydantic schemas — extracted from compliance/api/schemas.py.

Phase 1 Step 3: the monolithic ``compliance.api.schemas`` module is being
split per domain under ``compliance.schemas``. This module is re-exported
from ``compliance.api.schemas`` for backwards compatibility.
"""

from datetime import datetime, date
from typing import Optional, List, Any, Dict

from pydantic import BaseModel, ConfigDict, Field

from compliance.schemas.common import (
    PaginationMeta, RegulationType, ControlType, ControlDomain,
    ControlStatus, RiskLevel, EvidenceStatus,
)


# ============================================================================
# Requirement Schemas
# ============================================================================

class RequirementBase(BaseModel):
    article: str
    paragraph: Optional[str] = None
    title: str
    description: Optional[str] = None
    requirement_text: Optional[str] = None
    breakpilot_interpretation: Optional[str] = None
    is_applicable: bool = True
    applicability_reason: Optional[str] = None
    priority: int = 2


class RequirementCreate(RequirementBase):
    regulation_id: str


class RequirementResponse(RequirementBase):
    id: str
    regulation_id: str
    regulation_code: Optional[str] = None

    # Implementation tracking
    implementation_status: Optional[str] = "not_started"
    implementation_details: Optional[str] = None
    code_references: Optional[List[Dict[str, Any]]] = None
    documentation_links: Optional[List[str]] = None

    # Evidence for auditors
    evidence_description: Optional[str] = None
    evidence_artifacts: Optional[List[Dict[str, Any]]] = None

    # Audit tracking
    auditor_notes: Optional[str] = None
    audit_status: Optional[str] = "pending"
    last_audit_date: Optional[datetime] = None
    last_auditor: Optional[str] = None

    # Source reference
    source_page: Optional[int] = None
    source_section: Optional[str] = None

    created_at: datetime
    updated_at: datetime

    model_config = ConfigDict(from_attributes=True)


class RequirementListResponse(BaseModel):
    requirements: List[RequirementResponse]
    total: int


class PaginatedRequirementResponse(BaseModel):
    """Paginated response for requirements - optimized for large datasets."""
    data: List[RequirementResponse]
    pagination: PaginationMeta

