"""
Modelos ORM para gestión de localización
"""

from typing import Optional

from api.v1.common.base_models import TenantScopedMixin, TimestampMixin
from core.database import Base
from sqlalchemy import Integer, PrimaryKeyConstraint, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column


class Location(Base, TenantScopedMixin, TimestampMixin):
    """
    Modelo para la tabla Location - Localización
    """

    __tablename__ = "location"  # SLocalizacion
    __table_args__ = (
        PrimaryKeyConstraint("id", name="location_pkey"),
        UniqueConstraint("code", name="location_code_unique"),
        {"schema": "a24"},
    )

    # Primary key
    id: Mapped[int] = mapped_column(
        Integer, primary_key=True, autoincrement=True)

    # Location code (unique)
    code: Mapped[str] = mapped_column(String(5), nullable=False, unique=True)

    # Location description
    description: Mapped[Optional[str]] = mapped_column(String(200))

    def __repr__(self):
        return f"<Location(id={self.id}, code={self.code}, description={self.description})>"
