from datetime import datetime

from pydantic import BaseModel, EmailStr, Field


class UserRegister(BaseModel):
    email: EmailStr
    password: str = Field(min_length=6, max_length=128)


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


class UserPublic(BaseModel):
    id: int
    email: str
    rating: float
    points: int
    created_at: datetime

    class Config:
        from_attributes = True


class SessionPublic(BaseModel):
    id: int
    created_at: datetime
    expires_at: datetime
    is_active: bool

    class Config:
        from_attributes = True


class ExternalDataCreate(BaseModel):
    source: str = Field(min_length=1, max_length=128)
    payload: dict | str
    points_delta: int = 0
    rating_delta: float = 0.0


class ExternalDataPublic(BaseModel):
    id: int
    source: str
    payload: str
    created_at: datetime

    class Config:
        from_attributes = True
