from datetime import datetime
from typing import Optional
from uuid import UUID
from pydantic import BaseModel, ConfigDict, Field

class AuditLogCreate(BaseModel):
    """创建审计日志"""
    user_id: Optional[UUID] = None
    project_id: Optional[UUID] = None
    action: str
    resource_type: Optional[str] = None
    resource_id: Optional[str] = None
    ip_address: Optional[str] = None
    request_method: Optional[str] = None
    request_path: Optional[str] = None
    request_data: Optional[dict] = None
    response_status: Optional[int] = None

class AuditLogResponse(BaseModel):
    """审计日志响应"""
    id: UUID
    user_id: Optional[UUID]
    project_id: Optional[UUID]
    action: str
    resource_type: Optional[str]
    resource_id: Optional[str]
    ip_address: Optional[str]
    request_method: Optional[str]
    request_path: Optional[str]
    request_data: Optional[dict]
    response_status: Optional[int]
    timestamp: datetime
    
    model_config = ConfigDict(from_attributes=True)

class AuditLogQuery(BaseModel):
    """审计日志查询参数"""
    user_id: Optional[UUID] = None
    project_id: Optional[UUID] = None
    action: Optional[str] = None
    resource_type: Optional[str] = None
    start_time: Optional[datetime] = None
    end_time: Optional[datetime] = None
    skip: int = Field(default=0, ge=0)
    limit: int = Field(default=100, ge=1, le=1000)
