"""DTOs para el módulo de códigos de invitación."""

from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel, Field


class CreateInviteCodeDTO(BaseModel):
    company_id: Optional[int] = Field(
        None, description="Empresa destino (None = cualquier empresa del tenant)"
    )
    role: str = Field("user", description="Rol asignado al canjear el código")
    max_uses: Optional[int] = Field(None, description="Usos máximos (None = ilimitado)")
    expires_at: Optional[datetime] = Field(None, description="Expiración (None = sin expiración)")


class InviteCodeResponseDTO(BaseModel):
    id: int
    code: str
    tenant_slug: str
    company_id: Optional[int]
    role: str
    max_uses: Optional[int]
    uses_count: int
    expires_at: Optional[datetime]
    is_active: bool
    created_by: str
    created_at: datetime

    class Config:
        from_attributes = True


class ValidateInviteCodeResponseDTO(BaseModel):
    code: str
    tenant_slug: str
    company_id: Optional[int]
    role: str
    remaining_uses: Optional[int] = Field(
        None, description="Usos restantes; None = ilimitado"
    )
    expires_at: Optional[datetime]


class ConsumeInviteCodeResponseDTO(BaseModel):
    success: bool
    message: str
    tenant_slug: str
    company_id: Optional[int]
    role: str
