"""
Data models for simplified local-first versioning system.

Provides type-safe data structures for local cache management, sync operations,
and version metadata following CLAUDE.md principles.
"""

from dataclasses import dataclass
from datetime import datetime
from pathlib import Path
from typing import Optional


@dataclass
class FilterCriteria:
    """Filter criteria for reference data operations."""
    cloud_provider: str  # Required
    service: Optional[str] = None
    usage_family: Optional[str] = None
    resource_type: Optional[str] = None
    operation: Optional[str] = None
    usage_type: Optional[str] = None
    exact_match: bool = True  # Default to exact matching


@dataclass
class FlushResult:
    """Result of a flush operation on local cache."""
    records_removed: int
    local_changes_made: bool
    sync_reminder: str  # Message about needing to upload


@dataclass
class FlushPreview:
    """Preview of what would be removed in a flush operation."""
    records_to_remove: int
    affected_combinations: int
    sample_records: list  # Sample of records that would be removed


@dataclass
class CacheInfo:
    """Local cache metadata information."""
    file_path: Path
    file_size_mb: float
    checksum: str
    modified_time: datetime
    record_count: int
    has_local_changes: bool


@dataclass
class ManifestInfo:
    """S3 manifest metadata for sync tracking."""
    current_version: str  # Currently active version ID
    total_versions: int  # Total number of versions in S3
    last_sync: datetime  # When local cache last synced with S3
    sync_checksum: str  # Checksum of data when last synced
    last_operation: str  # "upload", "download", "restore", "rollback"
    created_by: str  # System/user that created this manifest state


@dataclass
class LocalManifest:
    """Local cache manifest for change tracking."""
    last_modified: datetime  # When local cache was last modified
    last_operation: str  # "add", "flush" - what local operation was done
    records_affected: int  # How many records were changed
    has_local_changes: bool  # Whether there are unsynced changes
    last_sync: Optional[datetime] = None  # When last synced with S3
    sync_version: Optional[str] = None  # Version ID synced with
    sync_checksum: Optional[str] = None  # Checksum of synced data


@dataclass
class SyncStatus:
    """Sync status comparison between local and S3."""
    is_synced: bool
    local_checksum: str
    remote_checksum: str
    local_modified: datetime
    remote_modified: datetime
    recommendation: str  # "upload", "download", "synced", "conflict"
    local_ahead: bool
    remote_ahead: bool


@dataclass
class VersionInfo:
    """S3 version metadata information."""
    version_id: str
    created_at: datetime
    file_size_mb: float
    operation: str  # "upload", "restore", "rollback", "manual"
    checksum: str
    is_current: bool = False


@dataclass
class UploadResult:
    """Result of uploading local changes to S3."""
    success: bool
    backup_version: str  # Version ID of backup created
    new_current_checksum: str
    error_message: Optional[str] = None


@dataclass
class RestoreResult:
    """Result of restoring a version."""
    success: bool
    restored_version: str
    backup_created: str  # Backup of previous current
    error_message: Optional[str] = None