from pydantic import BaseModel, Field
from typing import Optional, Dict, Any
from datetime import datetime


class StaffInfo(BaseModel):
    """Simplified staff information"""
    id: int
    username: str
    full_name: Optional[str] = None
    role_type: str
    
    class Config:
        from_attributes = True


class ActivityLogResponse(BaseModel):
    """Activity log response schema"""
    log_id: int
    chain_id: int
    staff_id: int
    staff: Optional[StaffInfo] = None
    action_type: str = Field(..., description="Type of action (e.g., CREATE_LISTING, UPDATE_LISTING)")
    entity_type: str = Field(..., description="Type of entity (e.g., LISTING, PRODUCT, CATEGORY)")
    entity_id: Optional[int] = None
    description: str
    action_metadata: Optional[Dict[str, Any]] = Field(None, alias="metadata", description="Additional metadata about the action")
    created_at: datetime
    
    class Config:
        from_attributes = True
        populate_by_name = True  # Allow both 'metadata' and 'action_metadata'


class ActivityLogListResponse(BaseModel):
    """List of activity logs with pagination"""
    logs: list[ActivityLogResponse]
    total: int = Field(..., description="Total number of logs matching the filters")
    skip: int
    limit: int

