from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime
from models.ticket import TicketType, TicketStatus, TicketPriority

class TicketBase(BaseModel):
    title: str = Field(..., min_length=1, max_length=200)
    description: str = Field(..., min_length=1)
    ticket_type: TicketType = Field(default=TicketType.OTHER)
    priority: TicketPriority = Field(default=TicketPriority.MEDIUM)

class TicketCreate(TicketBase):
    pass

class TicketUpdate(BaseModel):
    title: Optional[str] = Field(None, min_length=1, max_length=200)
    description: Optional[str] = Field(None, min_length=1)
    ticket_type: Optional[TicketType] = None
    status: Optional[TicketStatus] = None
    priority: Optional[TicketPriority] = None
    assigned_to: Optional[int] = None
    admin_notes: Optional[str] = None

class TicketResponse(TicketBase):
    id: int
    status: TicketStatus
    user_id: int
    assigned_to: Optional[int]
    screenshot_path: Optional[str]
    admin_notes: Optional[str]
    created_at: datetime
    updated_at: datetime
    resolved_at: Optional[datetime]
    
    # User information
    user_name: str
    user_email: str
    assigned_admin_name: Optional[str] = None
    
    class Config:
        from_attributes = True

class TicketAdminUpdate(BaseModel):
    status: Optional[TicketStatus] = None
    priority: Optional[TicketPriority] = None
    assigned_to: Optional[int] = None
    admin_notes: Optional[str] = None
