from pydantic import BaseModel, EmailStr, field_validator, Field, SecretStr
from pydantic_core.core_schema import FieldValidationInfo

class UserCreate(BaseModel):
    email: EmailStr
    first_name: str
    last_name: str
    password: str
    confirm_password: str
    business_name: str
    
    @field_validator("email")
    def email_must_contain_at_symbol(cls, v):
        if '@' not in v:
            raise ValueError("Entrer un email valide")
        return v
    
    @field_validator("password")
    def password_must_contain_at_least_8_characters(cls, v):
        if len(v) < 8:
            raise ValueError("Le mot de passe doit contenir au moins 8 caractères")
        return v
    
    @field_validator("business_name")
    def business_name_must_contain_at_least_3_characters(cls, v):
        if len(v) < 3:
            raise ValueError("Le nom de la société doit contenir au moins 3 caractères")
        return v
    
    @field_validator('confirm_password', mode='before')
    def passwords_match(cls, v, info: FieldValidationInfo):
        if 'password' in info.data and v != info.data['password']:
            raise ValueError('Les mots de passe ne correspondent pas')
        return v


class UserLogin(BaseModel):
    email: EmailStr
    password: str
    
class UserOut(BaseModel):
    email: EmailStr
    business_name: str
