from typing import Optional, List, Dict
from pydantic import BaseModel
from datetime import datetime
from app.models.backup import BackupType

class BackupRecordBase(BaseModel):
    filename: str
    backup_type: BackupType
    content_types: Optional[str] = None
    file_size: Optional[int] = None

class BackupRecordCreate(BackupRecordBase):
    file_path: str

class BackupRecord(BackupRecordBase):
    id: int
    created_at: datetime

    class Config:
        from_attributes = True

class BackupRecordList(BaseModel):
    total: int
    items: List[BackupRecord]

class BackupSettingsBase(BaseModel):
    auto_backup_enabled: bool
    backup_time: str # "HH:MM"

class BackupSettingsUpdate(BackupSettingsBase):
    pass

class BackupSettings(BackupSettingsBase):
    id: int
    last_backup_at: Optional[datetime] = None
    updated_at: datetime

    class Config:
        from_attributes = True

class MappingFileInfo(BaseModel):
    filename: str
    app_id: Optional[str] = None

class RestorePreviewResponse(BaseModel):
    csv_headers: List[str]
    db_columns: List[str]
    mapping_files: Optional[List[MappingFileInfo]] = None

class RestoreRequest(BaseModel):
    restore_type: str
    field_mapping: Dict[str, str]
    password: str
    sms_code: str
    selected_files: Optional[List[str]] = None # List of filenames to restore (for MAPPINGS)

class SendSmsRequest(BaseModel):
    captcha_id: str
    captcha_code: str
