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


class Legend(Base, TenantScopedMixin, TimestampMixin):
    __tablename__ = "legends"
    __table_args__ = (
        UniqueConstraint("code", "tenant_id", "company_id",
                         name="uq_legend_code"),
        {"schema": "a76"}
    )

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

    code: Mapped[int] = mapped_column(Integer, nullable=False)  # CLAVELEY
    
    description: Mapped[Optional[str]] = mapped_column(
        String(2000), nullable=True)  # DESCLEYENDA
