"""Data models for schema inference results."""

from typing import Dict, List, Any
from pydantic import BaseModel, Field


class FieldInfo(BaseModel):
    """Information about an inferred field."""
    name: str
    type: str
    nullable: bool = True
    description: str = ""


class InferredSchema(BaseModel):
    """Result of schema inference."""
    model_name: str
    fields: List[FieldInfo]
    source_file: str = ""
    source_type: str = Field(default="json", description="Source file type: json or csv")
    record_count: int = Field(default=0, description="Number of records analyzed")
    
    def to_pydantic_code(self, class_name: str = "Model") -> str:
        """Generate Pydantic model code."""
        lines = [
            "from pydantic import BaseModel",
            "from typing import Optional",
            "",
            f"class {class_name}(BaseModel):",
        ]
        
        for field in self.fields:
            field_type = f"Optional[{field.type}]" if field.nullable else field.type
            lines.append(f"    {field.name}: {field_type}")
        
        return "\n".join(lines)
