from pydantic import BaseModel, EmailStr, Field,field_validator
from src.constants import ApplicationUserRoleEnum
import re
from src.constants import TicketPriorityEnum
from typing import List, Optional




#Application user schemas


class AddUserRequest(BaseModel):
    email: EmailStr
    password: str = Field(min_length=8,max_length=15)

    @field_validator('password')
    @classmethod
    def validate_password(cls, value: str) -> str:
        if not re.search(r'[A-Z]', value):
            raise ValueError('Password must contain at least one uppercase letter')
        if not re.search(r'[a-z]', value):
            raise ValueError('Password must contain at least one lowercase letter')
        if not re.search(r'[!@#$%^&*(),.?":{}|<>_\-+=]', value):
            raise ValueError('Password must contain at least one special character')
        if not re.search(r'\d', value):  # optional: require digits
            raise ValueError('Password must contain at least one digit')
        return value
    
    full_name: str
    role: ApplicationUserRoleEnum
    is_2FA_required: bool = False




class TicketSchema(BaseModel):
    Issue_Type:Optional[str]
    Title:Optional[str]
    priority:Optional[TicketPriorityEnum]


# Pydantic model for creating/updating tags
class Tag(BaseModel):
    tag_name: str


class TagList(BaseModel):
    tags: List[Tag]